【问题标题】:skip multiple values for loop which is passing to a task ansible跳过传递给任务 ansible 的循环的多个值
【发布时间】:2023-04-03 05:24:01
【问题描述】:

如何从寄存器输出(来自上一个任务)传递的循环中过滤掉不需要的值

代码

# assume the list_one below register values.
list_one = [root, a, b, c]

- name: with_together
  debug:
    msg: "{{ item.0 }} - {{ item.1 }}"
  with_together:
    - "{{ list_one }}"
    - "{{ list_two }}"

我怎样才能只跳过 root 传递给 {{item.0}} ?

谢谢

【问题讨论】:

    标签: ansible ansible-2.x ansible-inventory ansible-facts ansible-template


    【解决方案1】:

    您可以添加如下条件

      - name: with_together
        debug:
          msg: "{{ item.0 }} - {{ item.1 }}"
        when: item.0 != 'root'
        with_together:
         - "{{ list_one }}"
         - "{{ list_two }}"
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 2023-03-14
      • 2021-10-03
      • 1970-01-01
      相关资源
      最近更新 更多