Here is an illustration of the difference for those interested.
- name: test loop constructs
hosts: localhost
gather_facts: false
become: false
vars:
my_list: [ one, two, three ]
tasks:
debug: var=item
loop:
-
‘{{ my_list }}’
-
name: construct 2
debug: var=item
loop: ‘{{ my_list }}’
% ansible-playbook -i localhost, loop.yml
PLAY [test loop constructs] ********************************************************************************************
TASK [construct 1] *****************************************************************************************************
ok: [localhost] => (item=[‘one’, ‘two’, ‘three’]) => {
“ansible_loop_var”: “item”,
“item”: [
“one”,
“two”,
“three”
]
}
TASK [construct 2] *****************************************************************************************************
ok: [localhost] => (item=one) => {
“ansible_loop_var”: “item”,
“item”: “one”
}
ok: [localhost] => (item=two) => {
“ansible_loop_var”: “item”,
“item”: “two”
}
ok: [localhost] => (item=three) => {
“ansible_loop_var”: “item”,
“item”: “three”
}
PLAY RECAP *************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Walter