# Same host in multiple host groups

**URL:** <https://forum.ansible.com/t/same-host-in-multiple-host-groups/28443>\
**Category:** Ansible Project\
**Created:** [August 28, 2018, 1:12pm UTC](https://forum.ansible.com/t/same-host-in-multiple-host-groups/28443 "2018-08-28T13:12:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![payam.mesgari](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@payam.mesgari](https://forum.ansible.com/u/payam.mesgari)\
**Post date:** [August 28, 2018, 1:12pm UTC](https://forum.ansible.com/t/same-host-in-multiple-host-groups/28443/1 "2018-08-28T13:12:40Z")

</div>

Hi,

I am experiencing something similar to this issue [Ansible group\_vars from inventory don’t support repeated hosts](https://github.com/ansible/ansible/issues/17243).

My main playbook is:

_ **site.yml** _

`

- name: Configure acceptance server  
hosts: acceptance  
roles:

- common  
tags: acceptance

- name: Configure production server  
hosts: production  
roles:

- common  
tags: production  
`

_ **hosts** _

`

[acceptance]  
127.0.0.1 ansible\_connection=local

[production]  
127.0.0.2 ansible\_connection=local

`

In the group\_vars I have the following files:

_ **acceptance** _

`

# Application

app\_name: snow\_proxy  
cert\_name: vcpe-le-snow-proxy-acc

# Web Server

## deploy\_ssl true for HTTPS, false for only HTTP

deploy\_ssl: true

## local directory SSL certificates should be located here

ssl\_certs\_dir: /home/mid/certs

`

**production**

`

# Application

app\_name: snow\_proxy  
cert\_name: vcpe-le-snow-proxy-acc

# Web Server

## deploy\_ssl true for HTTPS, false for only HTTP

deploy\_ssl: true

## local directory SSL certificates should be located here

ssl\_certs\_dir: /home/mid/prod/certs

`

When running the playbook I expect the correct set of variables will be loaded depending on the tag, but in both cases it seems the group\_vars are overriding each other because the same host is repeated in both groups.

`  
ansible-playbook -i hosts site.yml --tags acceptance

…  
Unable to find ‘/home/mid\*\*/prod/certs/\*\*vcpe-le-snow-proxy-acc.crt’ in expected paths.  
…  
`

`  
ansible-playbook -i hosts site.yml --tags production

…  
Unable to find ‘/home/mid\*\*/prod/certs/\*\*vcpe-le-snow-proxy-acc.crt’ in expected paths.  
…

`

---

<div class="post-metadata">

**Author:** ![ttwalto](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@ttwalto](https://forum.ansible.com/u/ttwalto)\
**Post date:** [August 28, 2018, 1:44pm UTC](https://forum.ansible.com/t/same-host-in-multiple-host-groups/28443/2 "2018-08-28T13:44:38Z")

</div>

What is the play that uses ssl\_certs\_dir?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 28, 2018, 1:50pm UTC](https://forum.ansible.com/t/same-host-in-multiple-host-groups/28443/3 "2018-08-28T13:50:39Z")

</div>

> I am experiencing something similar to this issue Ansible group\_vars from  
> inventory don't support repeated hosts  
> \<[https://github.com/ansible/ansible/issues/17243&gt;\](https://github.com/ansible/ansible/issues/17243&gt;%5C).
> 
> My main playbook is:
> 
> \*site.yml\*
> 
> - name: Configure acceptance server  
> &nbsp;&nbsp;hosts: acceptance  
> &nbsp;&nbsp;roles:  
> &nbsp;&nbsp;&nbsp;&nbsp;- common  
> &nbsp;&nbsp;tags: acceptance
> 
> - name: Configure production server  
> &nbsp;&nbsp;hosts: production  
> &nbsp;&nbsp;roles:  
> &nbsp;&nbsp;&nbsp;&nbsp;- common  
> &nbsp;&nbsp;tags: production
> 
> \*hosts\*  
> [acceptance]  
> 127.0.0.1 ansible\_connection=local
> 
> [production]  
> 127.0.0.2 ansible\_connection=local

From Ansible point of view this is to separate hosts and those hosts have separated variable as any other hosts in Ansible inventory.

> In the group\_vars I have the following files:
> 
> \*acceptance\*  
> # Application  
> app\_name: snow\_proxy  
> cert\_name: vcpe-le-snow-proxy-acc
> 
> # Web Server  
> ## deploy\_ssl true for HTTPS, false for only HTTP  
> deploy\_ssl: true  
> ## local directory SSL certificates should be located here  
> ssl\_certs\_dir: /home/mid/certs
> 
> \*production\*  
> # Application  
> app\_name: snow\_proxy  
> cert\_name: vcpe-le-snow-proxy-acc
> 
> # Web Server  
> ## deploy\_ssl true for HTTPS, false for only HTTP  
> deploy\_ssl: true  
> ## local directory SSL certificates should be located here  
> ssl\_certs\_dir: /home/mid/prod/certs
> 
> When running the playbook I expect the correct set of variables will be  
> loaded depending on the tag, but in both cases it seems the group\_vars are  
> overriding each other because the same host is repeated in both groups.
> 
> ansible-playbook -i hosts site.yml --tags acceptance
> 
> ....  
> Unable to find '/home/mid\*/prod/certs/\*vcpe-le-snow-proxy-acc.crt' in  
> expected paths.  
> ....
> 
> ansible-playbook -i hosts site.yml --tags production
> 
> ....  
> Unable to find '/home/mid\*/prod/certs/\*vcpe-le-snow-proxy-acc.crt' in  
> expected paths.  
> ....

This works on Ansible 2.6.3 and most if not all other versions, if not Ansible would have failed in many situations.

Are you sure you haven't hard coded the value in the common role?

---

<div class="post-metadata">

**Author:** ![payam.mesgari](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@payam.mesgari](https://forum.ansible.com/u/payam.mesgari)\
**Post date:** [August 28, 2018, 2:12pm UTC](https://forum.ansible.com/t/same-host-in-multiple-host-groups/28443/4 "2018-08-28T14:12:00Z")

</div>

I just checked the ansible version, it was quite old, version 2.2

I updated, now it is version 2.6  
The earlier problem is resolved, though I have another problem now.  
When running the playbook below, it throws error. I am running in **vagrant**.

`

- name: ensure Nginx is installed via the system package  
apt: name=nginx state=present update\_cache=yes  
sudo: yes

` `  
ansible-playbook -i hosts site.yml --tags acceptance

…

TASK [common : ensure Nginx is installed via the system package] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [195.121.71.148]: FAILED! =\> {“changed”: false, “msg”: “Failed to lock apt for exclusive operation”}  
…

`

Does this have to do with the user?

In my site.yml I have the following:

`

- name: Configure acceptance server  
hosts: acceptance  
user: vagrant  
roles:
- common  
tags: acceptance

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 28, 2018, 3:57pm UTC](https://forum.ansible.com/t/same-host-in-multiple-host-groups/28443/5 "2018-08-28T15:57:43Z")

</div>

If you check the top of the message you'll something about ignoring sudo or something like that.  
That's because sudo is deprecated if favor of become and partially removed in Ansible 2.6.

Change "sudo: yes" to "become: yes" and it should work.
