My requirement is pretty straight forward.
I wish to pass & read a set of string as array from ansible which is constructed by iterating over using with_items as show below.
- name: set_fact
set_fact:
fpath:
set_fact:
fpath: “{{ fpath + [ BASEPATH ~ ‘/’ ~ vars[item.split(‘.’)[1]] ~ ‘/’ ~ item | basename ] }}”
with_items:
- “{{ Source_Files.split(‘,’) }}”
vars:
fpath:
Using the set_fact module i collect the strings in a array variable called ‘fpath’ and then pass the variable to a shell script using shell module as below.
- shell: " ~/backup.sh ‘{{ fpath }}’ "
The challenge is that the passed string array fpath is unicode and is read as below in the shell script:
[u/tmp/file.js, u/var/test.txt, u/tmp/llo.rft]
Parsing this in unix shell script becomes challenging as evident by my post to this forum and I’m looking for a better solution to my requirement.