In the last chapter, we went over a fully functional Ansible playbook for deploying the Mezzanine CMS. That example exercised a number of 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.
Sometimes you want to run a particular task on the control machine instead of
on the remote host. Ansible provides the
local_action clause for tasks to
Imagine that the server we wanted to install Mezzanine onto had just booted, so that if we ran our playbook too soon, it would error out because the server hadn’t fully started up yet.
We could start off our playbook by invoking the
wait_for module to wait until
the SSH server was ready to accept connections before we executed the rest
of the playbook. In this case, we want this module to execute on our laptop, not
on the remote host.
The first task of our playbook would have to start off like this:
wait for ssh server to be running
wait_for port=22 host="
Note how we’re referencing
inventory_hostname in this task, which evaluates to the name of the remote
host, not localhost. That’s because the scope of these variables is still the
remote host, even though the task is executing locally.
If your play involves multiple hosts, and you use
local_action, the task will be executed multiple times, one for ...