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

问题描述 投票:6回答:2

使用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
ansible ansible-inventory
2个回答
3
投票

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

[webserver]
webserver

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

这个定义会引发警告:

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

[agent_x]
webservers                 # <-- 'webservers' is a host 

虽然这个不会:

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

[agent_x:children]
webservers                 # <-- 'webservers' is a group

引用来自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:条目来创建组的组

意思是你必须明确该组是否会列出hostsgroups


2
投票

之所以会发生这种情况,是因为您的广告资源中可能有相同的名称,例如以下广告资源

[webserver]
webserver
webserver1

我们有一个名为webserver的主机和同名的组,当你想要对网络服务器进行某些操作时可能会出现问题你不觉得吗?

如果您使用动态库存(例如ec2.py)时,该名称可能会重复到您的AWS envinronment中,我建议您更改此名称。

© www.soinside.com 2019 - 2024. All rights reserved.