0
您好我有以下动态/静态主机组进入其中大约有数据中心,环境信息ansible delegate_to变量
tag_Cluster_gateway_use1_qa_gw_proxy
我需要使用组条目上面delegate_to
两个变量通过内嵌像下面
- name: Copy Nginx Template
template:
src: nginx.conf.ctmpl.j2
dest: "/var/consul/template/web.conf.ctmpl"
delegate_to: "{{ item }}"
with_items: "groups.tag_Cluster_gateway_{{ datacenter }}_{{ stage }}_gw_proxy"
但是,当,当结果是
failed: [172.16.16.136] (item=groups.tag_Cluster_gateway_use1_qa_gw_proxy) => {"item": "groups.tag_Cluster_gateway_use1_qa_gw_proxy", "msg": "Failed to connect to the host via ssh.", "unreachable": true}
fatal: [172.16.16.136]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"_ansible_item_result": true, "item": "groups.tag_Cluster_gateway_use1_qa_gw_proxy", "msg": "Failed to connect to the host via ssh.", "unreachable": true}]}
我认为Ansible将groups.tag_Cluster_gateway_use1_qa_gw_proxy
作为主机条目而不是组条目。
与
delegate_to: "{{ item }}"
with_items: "{{ groups['tag_Cluster_gateway_{{ datacenter }}_{{ stage }}_gw_proxy'] }}"
也尝试和结果
[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error.: 'dict object' has no attribute
'tag_Cluster_gateway_{{ datacenter }}_{{ stage }}_gw_proxy'.
This feature will be removed in a future release. Deprecation warnings can
be disabled by setting deprecation_warnings=False in ansible.cfg.
fatal: [172.16.16.136]: FAILED! => {"failed": true, "msg": "'item' is undefined"}
但是,如果我提静态像groups.tag_Cluster_gateway_use1_qa_gw_proxy
它工作正常。
希望我为这个问题提供了足够的细节。请帮助我如何让变量通过deletage_to
通过主机组
delegate_to只能取单个主机而不是组。因此,delegate_to行中的{{item}}是主机? – Shasha99
@ Shasha99 {{item}}将在主机组上循环。如果我提到将它设置为像我配置的变量那么它工作正常。问题是变量,即使它显示它已经处理它不会作为组 – Irfad
好的,你可以手动ssh到你在delegate_to提到的主机?如果是,那么你在连接时使用密码? – Shasha99