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 }}"
答案 0 :(得分:0)
您必须使用when
(documentation)关键字作为条件,并使用吉纳滤波器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"