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.
Get Ansible Playbook Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.