Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: [WARNING]: Found both group and host with same name

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
like image 925
sdot257 Avatar asked May 30 '17 16:05

sdot257


People also ask

How do you mention hosts in ansible?

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.

WHAT IS group in ansible?

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.

What is host pattern in ansible?

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.


2 Answers

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.

like image 166
frntn Avatar answered Sep 21 '22 05:09

frntn


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.

like image 42
Paulo Victor Avatar answered Sep 21 '22 05:09

Paulo Victor