# command module

**URL:** <https://forum.ansible.com/t/command-module/34157>\
**Category:** Ansible Project\
**Created:** [November 5, 2020, 6:50am UTC](https://forum.ansible.com/t/command-module/34157 "2020-11-05T06:50:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shreya\_Bhardwaj](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Shreya\_Bhardwaj](https://forum.ansible.com/u/Shreya_Bhardwaj)\
**Post date:** [November 5, 2020, 6:50am UTC](https://forum.ansible.com/t/command-module/34157/1 "2020-11-05T06:50:06Z")

</div>

Hello Everyone,

I’m using the command module to run a few commands.  
I’m using the “creates” feature of the module as a check so that re running of command can be prevented, but it isn’t creating the file in the first place.

what could be the possible reason of it?

Thanks

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 5, 2020, 6:58am UTC](https://forum.ansible.com/t/command-module/34157/2 "2020-11-05T06:58:27Z")

</div>

> Hello Everyone,
> 
> I'm using the command module to run a few commands.  
> I'm using the "creates" feature of the module as a check so that re running of command can be prevented, but it isn't  
> creating the file in the first place.
> 
> what could be the possible reason of it?

The module doesn't create the file. The idea is that the command itself creates that file.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Shreya\_Bhardwaj](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Shreya\_Bhardwaj](https://forum.ansible.com/u/Shreya_Bhardwaj)\
**Post date:** [November 9, 2020, 11:30am UTC](https://forum.ansible.com/t/command-module/34157/3 "2020-11-09T11:30:12Z")

</div>

Yes, realized that later.

Thanks

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [November 8, 2022, 1:31pm UTC](https://forum.ansible.com/t/command-module/34157/4 "2022-11-08T13:31:55Z")

</div>

Yes! This is only used to avoid running the command if the file exists. The command you run must create the file if you intend to use the existence of the file to prevent running the command again.

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

The documentation for the **creates** parameter does not state that it creates the file for you.

Walter

---

<div class="post-metadata">

**Author:** ![Nobody\_Cares](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Nobody\_Cares](https://forum.ansible.com/u/Nobody_Cares)\
**Post date:** [November 8, 2022, 1:47pm UTC](https://forum.ansible.com/t/command-module/34157/5 "2022-11-08T13:47:06Z")

</div>

i did not say that file will be created… i did ask how to do that with command not creating files…

okay,

creating task to creating custom script (with: touch file.txt)

create new task running that script  
creating task removing scipt

looks easy

---

<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:41pm UTC](https://forum.ansible.com/t/command-module/34157/6 "2022-11-08T18:41:49Z")

</div>

> creating task to creating custom script (with: touch file.txt)

not really needed, can just use the ‘shell’ action and && , but you can if you really want to … you can write the script.

> create new task running that script

> creating task removing scipt

also not needed, the ‘script’ action will automatically copy + execute + remove the script from remote
