这是问题的示例:
库存文件:
[group1] www.example1.com
[group2] www.example1.com
group_vars文件:
group_vars/group1:
a_var: aaa
group_vars/group2:
a_var: bbb
如果我们运行此剧本:
- name: ...
hosts: group1
roles:
- ...
如果我们要部署到同一服务器上,则group_vars/group1和group_vars/group2中的变量会相互覆盖。
预期结果:
a_var = aaa
实际结果:
a_vars = bbb
似乎vars被解析并附加到主机上,而不是与该组呆在一起(因此,即使您不使用该组,group_vars也将合并,而最后一个组合并会成功!!!!)。这是正常行为吗?
最佳答案
is that a normal behavior ?
是的,如果主机位于多个组中,则仅接受一个组(后者)中的变量。
从docs:
It is ok to put systems in more than one group, for instance a server could be both a webserver and a dbserver. If you do, note that variables will come from all of the groups they are a member of, and variable precedence is detailed in a later chapter.
关于ansible - 当部署到不同组中的同一主机时,Ansible合并group_vars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39252751/