Use creates to simulate idempotency for command actions
The command action by default will run each time its invoked in a playbook (and each time the playbook is invoked). However you can make command idempotent by using the creates attribute.
For instance as part of an automated mysql install using ansible I run mysql _install _db to seed the initial databases. Rather than run that each time the playbook is called I check to see if the mysql database directory already exists (implying it has already run)
action: command /usr/bin/mysql_install_db --datadir ${datadir} creates=${datadir}/mysql
Written by Darryl Stoflet
Related protips
2 Responses
I should indicate that there is nothing simulated about this, it's quite real. If you're not running the command, you're not running the command :)
over 1 year ago
·
it is kind of simulated in that it doesn't REALLY tell you if the command has already been run - only if the file was created.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ansible
Authors
Misha Behersky
78.97K
tartansandal
73.31K
Related Tags
#ansible
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#