ansible - 当部署到不同组中的同一主机时,Ansible合并group_vars

标签 ansible

这是问题的示例:

库存文件:

[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/

相关文章:

json - 如何将特定数据附加到 JSON 数组

mysql - 使用ansible向mysql表中插入数据

python - pip install from requirements 工作但无法通过 ansible 找到相同的库

Ansible - host_list 拒绝解析/etc/ansible/hosts,因为它没有通过它的 verify_file() 方法

linux - Ansible:无法删除用户

Ansible:仅在未定义时设置变量

Ansible 主机名模块 - 添加操作系统支持

Ansible - 获取寄存器值的前几个字符

ansible - 如何在没有命令行标志的情况下在ansible中要求--ask-become-pass

Nginx、Ansible 和带有 Flask 应用程序的 uWSGI,内部服务器错误