Reputation: 103
I need to read from a config file which needs to contain a list. The list needs to be passed to a role as argument.
---
- name: run command on localhost
hosts: localhost
tasks:
- name: read variables from file
shell: cat {{ conf1/TMP.txt }}
register: contents
- name: role to trigger the run script process
hosts: otherhost
roles:
- { role: run_script, applist: "{{ contents }}" }
The content of the conf1/TMP.txt file is as follows:
[ 'a', 'b', 'c', 'd' ]
The above mentioned code segment is not working but the following code segment works:
---
- name: main yml file to trigger the whole process
hosts: otherhost
roles:
- { role: run_script, applist: [ 'a', 'b', 'c', 'd' ] }
Upvotes: 1
Views: 5493
Reputation: 376
Try using a lookup filter instead of a shell command. Example below..
---
- name: run command on localhost
hosts: localhost
tasks:
- set_fact:
contents: "{{ lookup('file', 'tmp.txt') }}"
- debug: var=contents
- name: role to trigger the run script process
hosts: localhost
roles:
- { role: foo, applist: "{{ contents }}" }
The output of debug should look like this
ok: [localhost] => {
"foo": [
"1",
"2",
"3",
"4"
]}
Upvotes: 3