> When I use* [all]*, as Ansible iterates through the hosts file can it
> search which Group the host belongs to and create an* /etc/hosts* from
> the
> group hostnames and IPs.
Space in group names is not allowed.
> For example:
>
> 1. Ansible interacts with: *kube-g2-master3*
>
> inventory_hostname = kube-g2-master3
>
> 2. Finds *kube-g2-master3* belongs* [Group 2]*
Groups in Ansible is just for grouping variables, and the grouping is
lost when Ansible is running.
What you can do is check if a host is in a group, but you would need to
check every group.
when: "'kube-g2-master3' in groups['group2']"
And the list of all group is in the special variable "group_names".
> 3. Creates */etc/hosts* on *kube-g2-master3* using the
> *inventory_hostname*
> and *ansible_hosts* from* [Group 2]*
>
> /etc/hosts
>
> kube-g2-master1 10.90.1.21
> kube-g2-master2 10.90.1.22
> kube-g2-master3 10.90.1.23
> kube-g2-node1 10.90.1.24
> kube-g2-node2 10.90.1.25
> kube-g2-lb 10.90.1.26
Since you are building a host list, all you need in the variable
groups['group2'] this is a list of all members in that group.
--
Kai Stian Olstad