[英]How can I overcome the set_fact variable for one host in multiple groups
Inventory File 库存文件
[dev:vars]
dev6
dev7
[dev6]
targethost1.xyz.com
[dev7]
targethost1.xyz.com
host_variables.yml host_variables.yml
dev6:
deploy_domain: "Dev6Domain"
WL_Admin: "DEV6WLAdmin"
WL_Managed: "DEV6Managed"
dev7:
deploy_domain: "Dev7Domain"
WL_Admin: "Dev7WLAdmin"
WL_Managed: "Dev7Managed"
The command I am trying to extract the myenv.deploy_domain from the playbook by using 我正在尝试使用以下命令从剧本中提取myenv.deploy_domain的命令
tasks:
- include_vars: host_variables.yml
- set_fact:
my_env: "{{ hostvars[inventory_hostname][group_names[1]] }}"
The dev6 and dev7 share the same host but with different domain and different other variables as defined in host_variables.yml. dev6和dev7共享同一主机,但具有不同的域和host_variables.yml中定义的其他变量。 So when I run the playbook for dev7, the my_env.deploy_domain shows me the value of dev6. 因此,当我为dev7运行剧本时,my_env.deploy_domain向我展示了dev6的价值。 How do I tell this piece of code to take only variables for current environment in play and match its specific hostname in the inventory? 如何告诉这段代码只使用当前环境中的变量,并使其与清单中的特定主机名匹配?
[dev:vars]
dev6
dev7
[dev6]
dev6host ansible_ssh_host=targethost1.xyz.com
[dev7]
dev7host ansible_ssh-host=targethost1.xyz.com
Now, the with the same host being shared for different environments, ansible treats all of them as seperate machines 现在,同一台主机共享给不同的环境,ansible将它们全部视为单独的计算机
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.