Adham_H
(Adham H)
September 16, 2014, 7:41am
1
Hey,
I am looking to concatenate variables in an array from a with_fileglob but i am not sure that set_fact works with loops
`
hosts : all
vars:
myfiles : [“old”]
tasks:
name: “facts”
set_fact:
myfiles: “{{ [item] | union(myfiles) }}”
with_items:
“new1”
“new2”
“new3”
name: “Debug”
debug:
var=myfiles
`
The output
"myfiles": [ "new3", "old" ]
Only the last item is added. any ideas ?
Just for starters, with version of ansible are you using?
I’d probably be tempted to just declare “my_files” as a list, in this particular case, it would make the playbook more readable.
I’m interested in the non-abstract use case though.
Adham_H
(Adham H)
September 16, 2014, 3:30pm
3
I use the dev branch. Unfortunately we use chef also. i hope will be replaced soon. Till then i have to use some data bags. So i have a bunch of json file i need to put in a list and start using some of variables.
Ah ok, I’m wondering if maybe you might want to write a custom lookup plugin that is something like “with_databag” ?
That’s a little abstract, but maybe the cleanest way to model it and show you are looping over a chef databag still.
That’s just a thought and may not entirely be appropriate, but would probably read cleaner as well.
Adham_H
(Adham H)
September 17, 2014, 7:10am
5
Michael,
I might go this way. Should be simple enough
Thanks