Hi Team,
I have the issue while running the Ansible playbook. There is no error with playbook, but the host.json will be in below format. the execution is happening only for one (Apple2), it is skipping (Apple1) even running with -l (limit) to apple1. Its picking the vars of Apple2.
FYI: Both are on the same host, but need two processes running with different vars.
hosts are unique in Ansible, and one thing to note is that the inventory doesn’t maintain hierarchy, like the YAML/JSON format may lead you to believe.
As such, group vars are merged down on to the hosts at inventory processing time. As such, your vars are applied down onto 10.10.10.1, with 1 group overwriting the other.
You can get around this by using a host alias, and then putting the address in ansible_host under vars. You could just make Apple1 and Apple2 those aliases, instead of making them groups:
Thanks for the info @Matt
I’m in need of running 5 such groups in each host, and I couldn’t make 5 alias for the single host. Is there any other work around.
You could still use groups, you just need unique hosts. So if you had 5 groups and 5 hosts, you would need 25 hosts basically. Remember that group vars merge down on the hosts, and the host is singular, so the same entry in multiple groups is the same host.