2 回答

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊
那么如何根據(jù)迭代的列表正確保存變量名中的操作結(jié)果呢?
你不需要。為with_items具有不同格式的任務(wù)注冊(cè)的變量,它們包含所有項(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}}"
- 2 回答
- 0 關(guān)注
- 1894 瀏覽
添加回答
舉報(bào)