Last Updated: February 25, 2016
·
3.688K
· dstoflet

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

2 Responses
Add your response

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 ·