Appending a variable's value to a list

9 views
Skip to first unread message

Johannes Kastl

unread,
Apr 13, 2016, 10:04:30 AM4/13/16
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

signature.asc
Reply all
Reply to author
Forward
0 new messages