How to execute alternating roles in Ansible?

前端 未结 1 1810
时光取名叫无心
时光取名叫无心 2021-01-16 21:07

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

相关标签:
1条回答
  • 2021-01-16 21:42

    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: "{{ values_to_pass | product(roles_to_include) | list }}"
    
    0 讨论(0)
提交回复
热议问题