Question:
I need to create an Ansible playbook to delete the *.web
files in a specific directory only if the files exists.
OS : cent OS, Redhat 5x, 6x.
I have tried the following with no success:
1 2 3 4 5 |
- stat: path=/opt/app/jboss/configuration/*.web register: web - shell: rm -rf /opt/app/jboss/configuration/*.web when: web.stat.exists |
Answer:
Here’s an example of “the fancy way”:
1 2 3 4 5 6 7 8 9 10 |
- find: paths: /opt/app/jboss/configuration patterns: "*.web" register: find_results - file: path: "{{ item['path'] }}" state: absent with_items: "{{ find_results['files'] }}" |