我需要从需要包含列表的配置文件中读取。该列表需要作为参数传递给角色。
<body <?php body_class(); ?>>
conf1 / TMP.txt文件的内容如下:
---
- 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 }}" }
上述代码段无效,但以下代码段有效:
[ 'a', 'b', 'c', 'd' ]
答案 0 :(得分:3)
尝试使用查找过滤器而不是shell命令。以下示例..
---
- 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 }}" }
debug的输出应该如下所示
ok: [localhost] => {
"foo": [
"1",
"2",
"3",
"4"
]}