maybe a stupid question, but how to print nicely a list
Ideally, i would like to print :
- all
- first
- second
But i’m not able to do it, please see 4 examples made :
-
hosts: localhost
gather_facts: no
vars:
found: -
all
-
first
-
second
tasks: -
name: test1
debug:
var: found -
name: test2
debug:
var: item
loop: “{{ found }}” -
name: test3
debug:
msg: “{{ found | to_nice_yaml }}” -
name: test4
debug:
msg: “{{ found | to_nice_yaml | indent(2, False) }}”
Result :
PLAY [localhost] *******************************************************************************************************************
TASK [test1] ***********************************************************************************************************************
ok: [localhost] => {
“found”: [
“all”,
“first”,
“second”
]
}
TASK [test2] ***********************************************************************************************************************
ok: [localhost] => (item=all) => {
“ansible_loop_var”: “item”,
“item”: “all”
}
ok: [localhost] => (item=first) => {
“ansible_loop_var”: “item”,
“item”: “first”
}
ok: [localhost] => (item=second) => {
“ansible_loop_var”: “item”,
“item”: “second”
}
TASK [test3] ***********************************************************************************************************************
ok: [localhost] => {
“msg”: “- all\n- first\n- second\n”
}
TASK [test4] ***********************************************************************************************************************
ok: [localhost] => {
“msg”: “- all\n - first\n - second\n”
}
The test3 is the nearest solution but ‘\n’ is not interpreted by the debug …