# Total Ansible n00b needing guidance on translating bash command to Ansible playlist

**URL:** <https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257>\
**Category:** Ansible Project\
**Created:** [August 15, 2017, 3:13pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257 "2017-08-15T15:13:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [August 15, 2017, 3:13pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/1 "2017-08-15T15:13:06Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [August 15, 2017, 3:17pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/2 "2017-08-15T15:17:58Z")

</div>

A method would be to get the return value from [http://docs.ansible.com/ansible/latest/find\_module.html](http://docs.ansible.com/ansible/latest/find_module.html) and then set the file state to absent.

---

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [August 15, 2017, 3:55pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/3 "2017-08-15T15:55:04Z")

</div>

Hi Andrew,

Thanks for the reply. I’m unfamiliar with how to reference the return value syntax. Would it be something like this?

---

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [August 15, 2017, 3:56pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/4 "2017-08-15T15:56:06Z")

</div>

Whoops, posted too soon.

---

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [August 15, 2017, 3:59pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/5 "2017-08-15T15:59:15Z")

</div>

So, something like this?

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [August 15, 2017, 4:06pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/6 "2017-08-15T16:06:07Z")

</div>

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 }}”  
‘’’

---

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [August 15, 2017, 5:03pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/7 "2017-08-15T17:03:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 15, 2017, 8:07pm UTC](https://forum.ansible.com/t/total-ansible-n00b-needing-guidance-on-translating-bash-command-to-ansible-playlist/25257/8 "2017-08-15T20:07:23Z")

</div>

Later in a playbook, yes, between playbooks, no.
