我正在嘗試撰寫一個應該在串列中執行一次的任務,例如:
- name: Create something that has an attribute with more than one values
some_module:
some_attribute: "{{ item }}"
run_once: true
loop:
- a
- b
但是這樣寫的任務會執行兩次,比如
- name: Create something that has an attribute with more than one values
some_module:
some_attribute: "a"
run_once: true
- name: Create something that has an attribute with more than one values
some_module:
some_attribute: "b"
run_once: true
我喜歡得到的是:
- name: Create something that has an attribute with more than one values
some_module:
some_attribute:
- a
- b
run_once: true
其中“some_attribute”也是一個串列。
我怎樣才能做到這一點?
謝謝
uj5u.com熱心網友回復:
但是這樣寫的任務會執行兩次
是的,這是預期的行為并按設計作業。
我怎樣才能做到這一點?...哪里
some_attribute也是一個串列。
你不能,除非你喜歡使用的模塊支持listas some_attribute。一個很好的例子是yum模塊——使用yum包管理器和注釋管理包
當與每個包一起使用時,將單獨處理,將串列直接傳遞給選項
loop:會更有效。name
您可以在我的類似問答鏈接下找到更多示例和測驗手冊。他們將更詳細地顯示該行為并解釋為什么會這樣。
類似問答
- 如何優化 Ansible playbook 在 SSH 連接方面的性能?
- 在 Ansible 中并行執行 localhost 任務
...除非您沒有提供更多背景資訊、詳細資訊并描述您嘗試實作的目標,至少是模塊名稱,否則無法給出更好的答案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/510408.html
標籤:循环可靠的
下一篇:Python嵌套for回圈,排序
