command module

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

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
       Racke

Yes, realized that later.

Thanks

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

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

Walter

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

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