Johannes Kastl
unread,Apr 13, 2016, 10:04:30 AM4/13/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
Hi everyone,
how to add the value of a variable to a list?
###########################
[...]
vars:
ansible_user: whatever
somelist:
- root
- "{{ ansible_user }}"
tasks:
- name: "Print complete list"
debug: msg="{{ somelist }}"
- name: "Print variable ansible_user"
debug: msg="Variable ansible_user is set to {{ ansible_user }}"
- name: "Print single items in list somelist"
debug: msg="Item is {{ item }}"
with_items:
- "{{ somelist }}"
###########################
I get an empty item or None (depending on what I try) in the third
task, even though the ansible_user variable evaluates correctly in the
second and shows up in the first task:
> TASK [Print complete list] *****************************************************
> ok: [localhost] => {
> "msg": [
> "root",
> "whatever"
> ]
> }
>
> TASK [Print variable ansible_user] *********************************************
> ok: [localhost] => {
> "msg": "Variable ansible_user is set to whatever"
> }
>
> TASK [Print single items in list somelist] *************************************
> ok: [localhost] => (item=root) => {
> "item": "root",
> "msg": "Item is root"
> }
> ok: [localhost] => (item=None) => {
> "item": null,
> "msg": "Item is "
> }
How to correctly add a string (that's what it should be), stored in a
value, to a list?
Thanks in advance.
Johannes