Helllo,制作一个包含的剧本的最佳方法是什么才能与播放给他的剧本在同一主机上播放? 我尝试用父主题名称在父playbook中声明一个变量,然后将其传递给包含的playbook,但是我收到一个错误,告诉我该变量未定义。
以下是我的剧本:
---
# Main staging configuration playbook
- vars:
host_name: "stage_ansible"
hosts: "{{ host_name }}"
remote_user: ubuntu
tasks:
- name: test connection
ping:
remote_user: ubuntu
- include: NginxDefinitions.yml
vars:
service_name: "interaction.qmerce.com"
env_name: "stage4"
host_name_pass: "{{ host_name }}"
...
和我收到的错误:
`ERROR! 'host_name' is undefined
答案 0 :(得分:1)
如果要定义主机运行时并避免在剧本上对其进行硬编码,则可以传递主机as extra variables on the command line.
为此,请从第一次播放中删除vars
定义,并将以下内容添加到ansible-playbook
命令行:
--extra-vars host_name=localhost
或当您有多个主机时:
--extra-vars '{"host_name":["host1","host2","host3"]}'