I'm pretty new in ansible and by now can't figure out how to make an idempotent task. E.g. file
. It simply doesn't have creates
or removes
. In command
module it does have creates
, but whenever I run the provisioner and the file (symbolic link) does exist, the ansible still marks the command as "ok", not "skipped".
Here's command
module example
- name: Firefox | link
command: ln -s /opt/firefox/firefox /usr/local/bin/firefox creates=/usr/local/bin/firefox
Always gets executed.
How do I get sure that the command won't be executed >=2 times given the node's state is already accomplished by 1st run?
Thank you!
That should work.
Actually i checked and it mostly works (see later), here's the complete playbook i used for testing it (not using firefox but the concept is the same):
Details:
You get a warning though:
If you want to be sure the link is correct, and change it only when needed (thus idempotent) the "correct" way, as for ansible's warning is to use the file module, here's an example: