Ansible:[警告]:找到具有相同名称的组和主机

luc*_*axi 8 ansible ansible-inventory

使用ec2.py库存脚本查询我的EC2实例.我一直收到以下警告标志.我如何通过修复造成问题的原因来压制它们?

[WARNING]: Found both group and host with same name: nex-1.XYZ.net
[WARNING]: Found both group and host with same name: admin-1.XYZ.net
[WARNING]: Found both group and host with same name: jenkinsmaster-1.XYZ.net
Run Code Online (Sandbox Code Playgroud)

frn*_*ntn 5

发现与主机和组同名的重用很容易:

[webserver]
webserver
Run Code Online (Sandbox Code Playgroud)

但这可能会比较棘手,因为有时只是忘记了:children在组定义中添加

此定义将发出警告:

[webservers]               # <-- 'webservers' is a group
web1
web2

[agent_x]
webservers                 # <-- 'webservers' is a host 
Run Code Online (Sandbox Code Playgroud)

虽然这不会:

[webservers]               # <-- 'webservers' is a group
web1
web2

[agent_x:children]
webservers                 # <-- 'webservers' is a group
Run Code Online (Sandbox Code Playgroud)

引用来自Ansible 2.4文档https://github.com/ansible/ansible/blob/stable-2.4/docs/docsite/rst/intro_inventory.rst#groups-of-groups-and-group-variables

也可以使用INI中的:children后缀或YAML中的children:条目来分组组

意思是您必须明确说明该组将列出hosts还是groups


Pau*_*tor 3

发生这种情况是因为您的库存中可能有相同的名称,例如以下库存:

[webserver]
webserver
webserver1
Run Code Online (Sandbox Code Playgroud)

我们有一个名为 Webserver 的主机,并且组中具有相同的名称,当您想要对 Web 服务器进行分组时可能会出现问题,您不觉得吗?

如果您使用动态清单(如 ec2.py)时发生这种情况,则名称可能会重复到您的 AWS 环境中,我建议您更改此设置。