【问题标题】:Ansible nested loops through inventories plus outer loop of a listAnsible 嵌套循环通过库存加上列表的外部循环
【发布时间】:2018-12-08 22:41:24
【问题描述】:

假设我有以下剧本:

---
- hosts: all
  gather_facts: False
  vars:
    group: 'dev'

  tasks:
  - name: Just loop through a group and group_vars
    debug:
      msg: 'group is {{group}} target is {{item.0}} port is {{item.1}}'
    loop: >
      {{ groups[group] |
         product(hostvars[groups[group][0]]["ports"]) |
         list }}

如果我将名为“组”的变量定义为列表而不是单个变量,我该如何更改循环部分?例如:

vars:
  group:
  - 'dev'
  - 'int'

感谢和问候。

史蒂夫

【问题讨论】:

    标签: loops ansible ansible-inventory


    【解决方案1】:
    loop: >
       {{ groups | dict2items | 
          selectattr("key", "in", group_list ) |
          map(attribute="value") | list |
          ### and then the rest of your pipeline }}
    

    我认为会做你想做的事

    【讨论】:

    • 嗨 Matthew...它不工作...尝试编写整个循环管道。
    猜你喜欢
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 1970-01-01
    相关资源
    最近更新 更多