我有一本剧本,我想在我的主机文件中定义一个字符串列表。
这是我的主机文件:
[dashboard]
1.2.3.4 dashboard_domain=test site_domain=['one','two','foo', 'bar']
这是我尝试使用列表文档编写的剧本:
---
- hosts: dashboard
gather_facts: False
remote_user: ubuntu
become: yes
tasks:
- name: ping
ping:
- debug:
msg: "Domain: {{dashboard_domain}}"
- debug:
msg: "Site: {{ item }}"
with_items: "{{site_domain}}"
但是运行此剧本ansible-playbook -i hosts ping.yml
会导致此错误:
任务:[调试] ********************************************* *******************
致命:[1.2.3.4] => with_items 需要一个列表或一个集合
这似乎是将定义的列表从主机文件传输到 playbook 的问题,因为直接在 playbook 中定义列表是有效的:
---
- hosts: dashboard
gather_facts: False
remote_user: ubuntu
become: yes
vars:
site_domain: ['one','two','foo', 'bar']
tasks:
#### APPLY HTTP-AUTH ####
- name: ping
ping:
- debug:
msg: "Domain: {{dashboard_domain}}"
- debug:
msg: "Site: {{ item }}"
with_items: "{{site_domain}}"