清单文件
[dev:vars]
dev6
dev7
[dev6]
targethost1.xyz.com
[dev7]
targethost1.xyz.com
host_variables.yml
dev6:
deploy_domain: "Dev6Domain"
WL_Admin: "DEV6WLAdmin"
WL_Managed: "DEV6Managed"
dev7:
deploy_domain: "Dev7Domain"
WL_Admin: "Dev7WLAdmin"
WL_Managed: "Dev7Managed"
我试图通过使用
从剧本中提取myenv.deploy_domain的命令tasks:
- include_vars: host_variables.yml
- set_fact:
my_env: "{{ hostvars[inventory_hostname][group_names[1]] }}"
dev6和dev7共享相同的主机,但具有不同的域和host_variables.yml中定义的其他不同变量。所以当我为dev7运行playbook时,my_env.deploy_domain会显示dev6的值。如何告诉这段代码只采用当前环境中的变量并匹配库存中的特定主机名?
答案 0 :(得分:0)
[dev:vars]
dev6
dev7
[dev6]
dev6host ansible_ssh_host=targethost1.xyz.com
[dev7]
dev7host ansible_ssh-host=targethost1.xyz.com
现在,同一个主机被共享用于不同的环境,ansible将所有这些主机视为单独的机器