是否有可能跳過Ansible with_items
循環操作符中的某些項目?在有條件的條件下跳過某些條件,但沒有生成額外的步驟?
剛例如:
- name: test task
command: touch "{{ item.item }}"
with_items:
- { item: "1" }
- { item: "2", when: "test_var is defined" }
- { item: "3" }
在這個任務我要創建文件2,只有當
test_var
定義
。
你可能想'when:(item == 2 and test_var defined)或item!= 2';或者它永遠不會執行其他項目 –
好的一點 - 這就是我得到的快速解決這個問題的方法。 ;) – nitzmahone
你只需要將'和'換成'或'? –