# Ansible 1.9 - how to combine variables from different sources

**URL:** <https://forum.ansible.com/t/ansible-1-9-how-to-combine-variables-from-different-sources/22615>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [September 22, 2016, 11:26am UTC](https://forum.ansible.com/t/ansible-1-9-how-to-combine-variables-from-different-sources/22615 "2016-09-22T11:26:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![P11](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@P11](https://forum.ansible.com/u/P11)\
**Post date:** [September 22, 2016, 11:26am UTC](https://forum.ansible.com/t/ansible-1-9-how-to-combine-variables-from-different-sources/22615/1 "2016-09-22T11:26:52Z")

</div>

Hi all,

so far most of our servers were running RHEL 6. We are going to prepare some RHEL 7 servers soon and I am now  
trying to rewrite our playbooks to be able cope with different releases of the same OS.  
There is of course the “old” way of doing this like:

`

- name: Install packages for RHEL6  
…  
when: ansible\_distribution == RedHat and ansible\_distribution\_major\_version == “6”

- name: Install packages for RHEL7  
…  
when: ansible\_distribution == RedHat and ansible\_distribution\_major\_version == “7”

`

But I am looking for more “elegant” way of doing it (still with Ansible 1.9 !!!) like:

`

- name: gather OS specific variables  
include\_vars: “{{ item }}”  
with\_items:

- “{{ ansible\_distribution }}/{{ ansible\_distribution\_major\_version}}.yml”

- common\_list\_of\_packages\_for\_both\_rhel\_releases.yml

- name: Install the required packages  
yum: name={{ item }} state=present  
with\_items: packages\_to\_install  
when: packages\_to\_install is defined  
tags: common

`where`packages\_to\_install ``variable is defined and combined from both files.`

I guess it won’t work because with\_items loop will overwrite the variable taken from

` `“{{ ansible\_distribution }}/{{ ansible\_distribution\_major\_version}}.yml”`

`with values taken from` **common\_list\_of\_packages\_for\_both\_rhel\_releases.yml** `

`In ansible 2 we can use jinja2 "combine" filter but we still use Ansible 1.9 ....`

Is there any elegant way in Ansible 1.9 to merge variables from different sources ?

Best regards  
P
