# Ansible loop & when - module 1 ### 1 layer loop ``` yaml - name: loop 1 layer vars: test: - test1 - test2 - test3 - test4 debug: msg: "{{ item }}" with_items: "{{ test }}" ``` ### nested loop ``` yaml - name: Hello World # 任務端變數優先級別高於主playbook vars: test: - test1 - test2 - test3 - test4 demo: - demo1 - demo2 - demo3 xyz: - xyz1 - xyz2 debug: msg: "{{ item[0] }}, {{ item[1] }}, {{ item[2] }}" verbosity: 0 with_nested: - "{{ test }}" - "{{ demo }}" - "{{ xyz }}" ``` ### condition when ``` yaml - name: Hello World # 任務端變數優先級別高於主playbook vars: seq: - 1 - 2 - 3 - 4 debug: msg: "{{ item }}" verbosity: 0 with_items: "{{ seq }}" when: item >=3 ``` ###### tags: `Ansible module`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up