Adding pre-tasks and post-tasks to playbooks
We would like to print status messages before and after we begin applying Nginx. Let's add it to our www.yml
playbook with the pre_tasks
and post_tasks
parameters:
--- - hosts: www remote_user: vagrant sudo: yes pre_tasks: - shell: echo 'I":" Beginning to configure web server..' roles: - nginx post_tasks: - shell: echo 'I":" Done configuring nginx web server...'
In the preceding example, we only printed some messages using the echo
command. However, we can create tasks using any of the modules available with Ansible, which can run before, or after, applying roles.