}

Ansible: separate group_vars being overwritten when deploying to same host

Created:

With ansible 1.6.1 using Mac OSX group_vars are overwritten by another group when sharing the same host. But it's very probable this will be seen on other versions and OSes.

Example hosts file:

[service1]
www.example1.com

[service2]
www.example2.com

Using these group_vars:

group_vars/service1:
    database_host: "www.test1.com"
    database_port:  3306

group_vars/service2:
    database_host: "www.another_host.com"
    database_port:  3306

Ansible is running this playbook:

- hosts: service1
  remote_user: root

The variables from group_vars/service1 and group_vars/service2 overwrite each other if we're deploying to the same server. This means service1 will get service2 groups variables and get the incorrect database host and port.

group_vars should not be overwritten by another group when sharing the same host

Solution

To get around these, add DNS entries (aliases to www.example1.com) so our host looks like:

[service1]
www.example1.com

[service2]
www.example2.com

Use a CNAME for the same hostname or an IP address. This is the only workaround currenttly.

The error appears when you are using Ansible Tower, because you're wasting a license with such CNAME's.