Forgive my newbie question, but I would like to execute three tasks and use two roles in a playbook, in the order:
This is what I have so far (task, role, task):
--- - name: Task Role Task hosts: 127.0.0.1 connection: local gather_facts: false pre_tasks: - name: Do this task first foo: roles: - role: this role second foo: post_tasks: - name: Do this task third foo:
Is this possible or should I be changing my tasks into roles?
Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.
When you execute a playbook, in each play, all roles will be executed first, followed by the tasks, top down in the order that they are written.
I recommend you create roles for post and pre tasks for you ansible.
Your site.yml must be some like this:
--- - hosts: localhost remote_user: "{{remote_user}}" sudo: yes gather_facts: false roles: - pre - main_role - post
in roles folder you must have three roles, pre, post and main_role.
Each "hosts:"-block will be executed one by one. So you can use multiple blocks to force the desired execution order:
--- - hosts: 127.0.0.1 tasks: - name: Do this task first - hosts: 127.0.0.1 roles: - role: this role second - hosts: 127.0.0.1 tasks: - name: Do this task third
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With