Question:
Forgive my newbie question, but I would like to execute three tasks and use two roles in a playbook, in the order:
- task
- role
- task
- role
- task
This is what I have so far (task, role, task):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
--- - 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?
Answer:
I recommend you create roles for post and pre tasks for you ansible.
Your site.yml must be some like this:
1 2 3 4 5 6 7 8 9 10 |
--- - 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.