如何使等到列出的项目匹配?

时间:2018-07-28 09:46:24

标签: loops ansible stdout

studout.lines是一个数字列表,这些数字从1更改为8,如何编写循环,并且无法等待列表中的所有值都变为8

  

ie {“ 8”,“ 8”,.............? }

{
        "1",

        "2",

        "3",

        "1",

        "6",

        "6",

        "7",

        "7",
}

- name read the status file  ---
  hosts: win
  tasks:
  - name: Get
    win_shell: Get-Content C:\\temp\\status.txt
    register: value

  - name: Get-status-code
    set_fact:
      code: "{{ value.stdout_lines|list }}"

  - name: debug
    debug:
      msg: "{{ item }}"
    with_items: "{{ code }}"

1 个答案:

答案 0 :(得分:0)

您必须使用whendocumentation)关键字作为条件,并使用吉纳滤波器unique。我还删除了循环,因为unique适用于整个列表。

- name read the status file  ---
  hosts: win
  tasks:
  - name: Get
    win_shell: Get-Content C:\\temp\\status.txt
    register: value

  - name: Get-status-code
    set_fact:
      code: "{{ value.stdout_lines|list }}"

  - name: debug
    debug:
      msg: "{{ code }}"
    when: code|unique == "8"