跳过传递给任务的循环的多个值ansible

问题描述 投票:0回答:1

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

代码

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

我如何仅跳过传递到{{item.0}}的root

谢谢

ansible ansible-2.x ansible-inventory ansible-facts ansible-template
1个回答
0
投票

您可以添加如下的when条件

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

© www.soinside.com 2019 - 2024. All rights reserved.