In the preceding chapter, we went over a fully functional Ansible playbook for deploying the Mezzanine CMS. That example used some common Ansible features, but it didn’t cover all of them. This chapter touches on those additional features, which makes it a bit of a grab bag.
initialize the database
createdb --noinput --nodata
We got around this problem by invoking several
django manage.py commands that
were idempotent, and that did the equivalent of
createdb. But what if we didn’t
have a module that could invoke equivalent commands? The answer is to use
failed_when clauses to change how Ansible identifies that a
task has changed state or failed.
First, we need to understand the output of this command the first time it’s run, and the output when it’s run the second time.
Recall from Chapter 4 that to capture the output of a failed task, you add a
register clause to save the output to a variable and a
failed_when: False clause so that the execution doesn’t stop even if the module returns failure. Then add a
debug task to print out the variable, and finally a
fail clause so that the playbook stops ...