# group\_vars values overriden for repeating servers

**URL:** <https://forum.ansible.com/t/group-vars-values-overriden-for-repeating-servers/21199>\
**Category:** Ansible Project\
**Created:** [April 18, 2016, 6:37pm UTC](https://forum.ansible.com/t/group-vars-values-overriden-for-repeating-servers/21199 "2016-04-18T18:37:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manoj\_Badam](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@Manoj\_Badam](https://forum.ansible.com/u/Manoj_Badam)\
**Post date:** [April 18, 2016, 6:37pm UTC](https://forum.ansible.com/t/group-vars-values-overriden-for-repeating-servers/21199/1 "2016-04-18T18:37:31Z")

</div>

Hi Team,

I’m a newbie to ansible, trying to complete this project for opening firewall ports. Below is my project structure

> - group\_vars
> - dbserver
> - webserver
> - applicationserver
> - host\_vars
> - roles
> - Common
> - files
> - app.app
> - handlers
> - main.yml
> - tasks
> - main.yml
> - hosts
> - site.yml

Contents of /hosts

[dbserver]  
host1 ansible\_ssh\_host=10.10.10.1  
host2 ansible\_ssh\_host=10.10.10.2

[webserver]  
host2 ansible\_ssh\_host=10.10.10.2

host3 ansible\_ssh\_host=10.10.10.3

[applicationserver]  
host1 ansible\_ssh\_host=10.10.10.1

host3 ansible\_ssh\_host=10.10.10.3

Contents of /group\_vars/dbserver

---

<div class="post-metadata">

**Author:** ![Dejay\_Clayton](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@Dejay\_Clayton](https://forum.ansible.com/u/Dejay_Clayton)\
**Post date:** [May 12, 2016, 8:39pm UTC](https://forum.ansible.com/t/group-vars-values-overriden-for-repeating-servers/21199/2 "2016-05-12T20:39:22Z")

</div>

How are you invoking the playbook? Just because a host is in two groups, doesn’t mean it will execute the logic for both groups.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 13, 2016, 8:32pm UTC](https://forum.ansible.com/t/group-vars-values-overriden-for-repeating-servers/21199/3 "2016-05-13T20:32:19Z")

</div>

The problem is that the list called firewallports gets overwritten by  
whatever vars file is processed last.

For example, first it gets set to list from databases var file, then  
to webserver list.

I do not know if it is possible to tell ansible to add lists together  
automatically.

Quick and dirty: I would name the lists differently, and duplicate the  
task:

- name: add database ports to the firewall  
&nbsp;&nbsp;firewalld: port={{ item }} permanent=true zone=work state=enabled  
&nbsp;&nbsp;with\_items: "{{ db\_firewallports }}"  
&nbsp;&nbsp;when: db\_firewallports is defined

- name: add webserver ports to the firewall  
&nbsp;&nbsp;firewalld: port={{ item }} permanent=true zone=work state=enabled  
&nbsp;&nbsp;with\_items: "{{ web\_firewallports }}"  
&nbsp;&nbsp;when: web\_firewallports is defined

Or join all lists together before the task into another list:  
set\_fact: firewallports= db\_firewallports + web\_firewallports  
(or something in this manner)

Johannes

---

<div class="post-metadata">

**Author:** ![Dejay\_Clayton](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@Dejay\_Clayton](https://forum.ansible.com/u/Dejay_Clayton)\
**Post date:** [May 16, 2016, 8:55pm UTC](https://forum.ansible.com/t/group-vars-values-overriden-for-repeating-servers/21199/4 "2016-05-16T20:55:12Z")

</div>

This behavior seems like it was changed recently, when the default in `ansible.cfg` changed from `hash_behavior=merge` to `hash_behavior=replace`.

Changing the value back to `merge` seems to work for many circumstances, but beware some caveats that were documented here:

[https://groups.google.com/forum/#!topic/ansible-project/cDWcbgJz1Hs](https://groups.google.com/forum/#!topic/ansible-project/cDWcbgJz1Hs)

Ansible makes me want to go back to Bash-based deployments.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 16, 2016, 9:49pm UTC](https://forum.ansible.com/t/group-vars-values-overriden-for-repeating-servers/21199/5 "2016-05-16T21:49:15Z")

</div>

The default has always been replace.
