2

We have Apache setup chrooted, so we can multiple apache on single directory for multiple httpd instance. I have added all the different groups with the instance name in inventory but their hosts are same.

While I am running tasks on one httpd instance, it takes groups vars of different group even though the hosts are same in all groups.

Dave M
  • 4,514
  • 22
  • 31
  • 30
blue_meme
  • 31
  • 1
  • 4
  • 1
    Just add a custom name for host and bind to ip using ansible_host. The response is here. https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#hosts-and-non-standard-ports – Mihai R Jun 06 '19 at 08:34

2 Answers2

3

This answer can help: Ansible same host on different groups with group_vars

Try overriding host variables each time it is required with "vars_files":

hosts: {{ group_name }}
vars_files:
 - group_vars/{{ group_name }}.yml
tasks:
TheDESTROS
  • 385
  • 3
  • 10
1

I have done another workaround.

I have added entries in /etc/hosts with different hostname but with same ips like below.

10.0.0.2 apache1
10.0.0.3 apache2
10.0.0.2 newapache1
10.0.0.3 newapache2

also i have added in inventory like below

[apache]
apache1
apache2

[newapache]
newapache1
newapache2

with same name you can create the groupvars with different details for same server.

Its not correct solution but for small setup its work great.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
blue_meme
  • 31
  • 1
  • 4