Hi,
I’m trying to run the following nested bash command: rm $( locate somefile ) but Ansible is kicking back an error asking me to use “state=absent” instead. How do I execute this while I’m searching for the potential location of “somefile” at the same time? And is this the correct location for asking these kinds of questions?
Thanks!
A method would be to get the return value from http://docs.ansible.com/ansible/latest/find_module.html and then set the file state to absent.
Hi Andrew,
Thanks for the reply. I’m unfamiliar with how to reference the return value syntax. Would it be something like this?
Something like this… assuming email does not mess it up to much… there are likely better ways but that is the 2 minute try
‘’’
-
name: find files
find:
paths: “/tmp”
patterns: “lala”
recurse: “yes”
file_type: “file”
register: find_result
-
name: remove found files
file:
path: “{{ item.path }}”
state: absent
with_items: “{{ find_result.files }}”
‘’’
Thanks Andrew. I’ll give that a try. Out of curiosity, does Ansible allow for output stored as variables to be referenced later in a Playbook?
Later in a playbook, yes, between playbooks, no.