2016-10-28 150 views
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通过主机组

+0

delegate_to只能取单个主机而不是组。因此,delegate_to行中的{{item}}是主机? – Shasha99

+0

@ Shasha99 {{item}}将在主机组上循环。如果我提到将它设置为像我配置的变量那么它工作正常。问题是变量,即使它显示它已经处理它不会作为组 – Irfad

+0

好的,你可以手动ssh到你在delegate_to提到的主机?如果是,那么你在连接时使用密码? – Shasha99

回答

0

你的问题是很久以前,所以我认为它不再是一个问题。如果它仍然是,请尝试以下操作:

delegate_to: "{{ item }}" 
with_items: "groups['tag_Cluster_gateway_{{ datacenter }}_{{ stage }}_gw_proxy']" 

的{{}}围绕整个声明支架让整个“标签_..._代理”语句为变量ansible搜索。 Ansible似乎仍试图用整个语句替换{{item}},这就是为什么错误消息指出“'item'未定义”