How to execute alternating roles in Ansible?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

How to execute alternating roles in Ansible?



I need to somehow loop over a list of variables and execute both of the below roles once for each iteration, on each iteration passing a variable to the role. For example, given a variable list of 100-101, I need to execute in the order role1:100, role2:100, role1:101, role2:101. The variables 100-100 should be passed to the tasks inside the role.


---
- hosts: group1
tasks:
- include_role:
name: role1

- hosts: group2
tasks:
- include_role:
name: role2



I was looking at the below answer as a possible solution but I am not sure how to adapt it to my needs. Can the above scenario be accomplished in Ansible?



Ansible: How to iterate over a role with an array?




1 Answer
1



Loop over the Cartesian product of variables and role names:


vars:
roles_to_include:
- role1
- role2
values_to_pass:
- 100
- 101

tasks:
- include_role:
name: " item.1 "
vars:
my_variable: " item.0 "
loop: " list "






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

PySpark count values by condition

Mass disable jenkins jobs