Using the ec2.py
inventory script to query against my EC2 instances. I keep getting the following warning signs. How can i suppress them by fixing what's causing the issue?
[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
Devices or hosts are referenced by their DNS name or with the ansible inventory ip address variable. Hosts can be defined either by IP address or DNS name or if DNS is not resolvable using the ansible_host command. Multiple servers or network devices can be referenced in a playbook by referencing the group name.
Group variables are a convenient way to apply variables to multiple hosts at once. Before executing, however, Ansible always flattens variables, including inventory variables, to the host level. If a host is a member of multiple groups, Ansible reads variable values from all of those groups.
ansible webservers -m service -a "name=httpd state=restarted" A pattern usually refers to a set of groups (which are sets of hosts) – in the above case, machines in the “webservers” group.
Spotting the reuse of the same name as host and group is easy :
[webserver]
webserver
But it might be trickier because sometimes it's just you have forgotten to add the :children
in your group definition
This definition will rise a Warning :
[webservers] # <-- 'webservers' is a group
web1
web2
[agent_x]
webservers # <-- 'webservers' is a host
While this one won't :
[webservers] # <-- 'webservers' is a group
web1
web2
[agent_x:children]
webservers # <-- 'webservers' is a group
Quote from ansible 2.4 documentation https://github.com/ansible/ansible/blob/stable-2.4/docs/docsite/rst/intro_inventory.rst#groups-of-groups-and-group-variables
It is also possible to make groups of groups using the :children suffix in INI or the children: entry in YAML
Meaning you have to be explicit whether the group will list hosts
or groups
.
It happens because you probably have the same names into your inventory, for example this follow inventory:
[webserver]
webserver
webserver1
We have one host called webserver and the same name into group, could be a problem when you want to do something to group webserver don't you think?
If it happens when you use Dynamic Inventory like ec2.py the name probably is duplicated into your AWS envinronment, I recommend you change this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With