Clear Your Production Servers Cache Using Ansible

Simple script to clear the production cache and set the read/write permissions.
after the cache is cleared, the permission are set so the www server can access them... note the order is important, cache is cleared first, then perms set on the folders...

you'll need to change the following items to suit your flavour of linux:

    path: "/srv/www/htdocs/var/cache"
    owner: wwwrun
    group: www
---
- name: Clear Applications Production Cache
  become: true
  hosts: www
  remote_user: root

  tasks:
    - name: Clear production cache
      command: php bin/console cache:clear --env=prod --no-warmup
      args:
        chdir: /srv/www/htdocs
      register: result
      changed_when: "'Cache cleared' in result.stdout or 'Clearing the cache' in result.stdout"

    - name: Show output
      debug:
        var: result.stdout_lines

    - name: Set ownership of cache folder to wwwrun:www
      file:
        path: "/srv/www/htdocs/var/cache"
        owner: wwwrun
        group: www
        recurse: yes
        state: directory

    - name: Set ownership of log folder to wwwrun:www
      file:
        path: "/srv/www/htdocs/var/log"
        owner: wwwrun
        group: www
        recurse: yes
        state: directory