1 回答

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個贊
那么,如何根據(jù)我遍歷的列表將操作結(jié)果正確保存在變量名稱中?
不用了 為with_items具有不同格式的任務(wù)注冊的變量,它們包含所有項(xiàng)目的結(jié)果。
- hosts: localhost
gather_facts: no
vars:
images:
- foo
- bar
tasks:
- shell: "echo result-{{item}}"
register: "r"
with_items: "{{ images }}"
- debug: var=r
- debug: msg="item.item={{item.item}}, item.stdout={{item.stdout}}, item.changed={{item.changed}}"
with_items: "{{r.results}}"
- debug: msg="Gets printed only if this item changed - {{item}}"
when: item.changed == true
with_items: "{{r.results}}"
- 1 回答
- 0 關(guān)注
- 800 瀏覽
添加回答
舉報