首页 > 解决方案 > 跳过传递给任务 ansible 的循环的多个值

问题描述

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

代码

# 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}} ?

谢谢

标签: ansibleansible-2.xansible-inventoryansible-factsansible-template

解决方案


您可以添加如下条件

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


推荐阅读