# how to run command that cannot create files?

**URL:** <https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317>\
**Category:** Ansible Developer\
**Created:** [November 8, 2022, 4:55pm UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317 "2022-11-08T16:55:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philipp\_Ewald](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@Philipp\_Ewald](https://forum.ansible.com/u/Philipp_Ewald)\
**Post date:** [November 8, 2022, 4:55pm UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317/1 "2022-11-08T16:55:25Z")

</div>

I dont want to create a script placing files or removing files.... just to run one command...

any ideas?

---

<div class="post-metadata">

**Author:** ![td784](https://avatars.discourse-cdn.com/v4/letter/t/aeb1de/32.png) [@td784](https://forum.ansible.com/u/td784)\
**Post date:** [November 8, 2022, 5:01pm UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317/2 "2022-11-08T17:01:03Z")

</div>

The ansible file module?

[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html)

---

<div class="post-metadata">

**Author:** ![Philipp\_Ewald](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@Philipp\_Ewald](https://forum.ansible.com/u/Philipp_Ewald)\
**Post date:** [November 8, 2022, 5:17pm UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317/3 "2022-11-08T17:17:41Z")

</div>

🙂

try this to explain new employees 😃 you need to place a file there, otherwise the command will be execute again :DDDDD

for me this is a bug

but ok i will do it with extra steps.... if everyone else is happy with that solution, i'm fine with that

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [November 8, 2022, 6:14pm UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317/4 "2022-11-08T18:14:43Z")

</div>

- shell:  
cmd: do\_something && touch /etc/do\_something/done  
creates: /etc/do\_something\_done

Easy peasy. This was recommended before, although no one explicitly wrote it out.

Otherwise, do a task before, to actually evaluate whether you need to run the command in the first place, instead of relying on the existence of a file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 8, 2022, 6:34pm UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317/5 "2022-11-08T18:34:09Z")

</div>

Tracking files that are not the normal side effect of a command are a  
poor way to track if a command was executed, the best way is to track  
the expected side effect of such a command (creates/removes does this  
by assuming those files are created/removed by the command's  
execution). There are other side effects that you can track, but hard  
to build them all into the command/shell modules (open port/service  
running/package installed/etc) but there are plenty of other actions  
that can query this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 8, 2022, 6:35pm UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317/6 "2022-11-08T18:35:45Z")

</div>

Also, if the built in command does not do exactly what you want, you  
are free to create your own custom version, it just not make sense for  
this in the core offering.

---

<div class="post-metadata">

**Author:** ![Philipp\_Ewald](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@Philipp\_Ewald](https://forum.ansible.com/u/Philipp_Ewald)\
**Post date:** [November 9, 2022, 9:46am UTC](https://forum.ansible.com/t/how-to-run-command-that-cannot-create-files/37317/7 "2022-11-09T09:46:40Z")

</div>

> - shell:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd: do\_something && touch /etc/do\_something/done  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;creates: /etc/do\_something\_done

This is the best solution. But why does i need to ask the Mailing list do get this? why ansible cant do this by itself? or why is this solution not in documentation?

> Otherwise, do a task before, to actually evaluate whether you need to run  
> the command in the first place, instead of relying on the existence of a  
> file.

for me its funny how complicated it is to just run a command... (known workarounds are not easy to access...)

But OK, everybody + developer are fine with that bug
