# OS variables variance

**URL:** <https://forum.ansible.com/t/os-variables-variance/15660>\
**Category:** Ansible Project\
**Tags:** windows, rhel, ubuntu\
**Created:** [July 13, 2014, 6:52pm UTC](https://forum.ansible.com/t/os-variables-variance/15660 "2014-07-13T18:52:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leibo](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Leibo](https://forum.ansible.com/u/Leibo)\
**Post date:** [July 13, 2014, 6:52pm UTC](https://forum.ansible.com/t/os-variables-variance/15660/1 "2014-07-13T18:52:51Z")

</div>

I would gladly get some advice here.

First, Ansible is so great - I replaced my Puppet proviosning for our UNIX hosts in a few days and everything is working so well and easy to maintain.

We support **AIX, HP-UX, Solaris** and **Linux** (_RedHat, Suse, Ubuntu_) so I have a commands variance between OS and also between OS variants.  
**Windows** clients support is so so so so asked around here (simple zip extracting module, commands execution)

I use roles and at the moment I took all different shared roles parameters and shell command paths into param files at playbooks/vars/AIX.yml, HP-UX.yml and so…

For Linux - I have Linux.yml, Redhat\_7.yml and Suse.yml for example as some commands are different between RHEL 5-6, RHEL 7, Ubuntu and Suse and some are the same.

In my playbook I use the vars\_files feature as I found in the docs example below to match for the specific OS version or OS type or Linux in general:

```auto
vars_files:
    - "vars/common.yml"
    - ["vars/{{ ansible_os_family }}.yml", "vars/os_defaults.yml"]

```

It works well but introduces duplication as the first matching file is selected and I need the non different parameters inside this file too…

**First question** , in the above example, common.yml parameter X will get overidden by {{ansible\_os\_family}}.yml defined parameter X?

**Second question** , I would like to separate parameters of OS commands to one file, Application X to another and so…

I get a real big section of this vars\_files that is very ugly to copy paste for each playbook…

Can you suggest a better way to handle this please?

Thanks

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 13, 2014, 8:07pm UTC](https://forum.ansible.com/t/os-variables-variance/15660/2 "2014-07-13T20:07:37Z")

</div>

“It works well but introduces duplication as the first matching file is selected and I need the non different parameters inside this file too…”

Not sure what you mean by “non-different parameters”.

“ **First question** , in the above example, common.yml parameter X will get overidden by {{ansible\_os\_family}}.yml defined parameter X?”

Yes. It comes later.

“ **Second question** , I would like to separate parameters of OS commands to one file, Application X to another and so…”

Then consider using group\_vars/ variables for these application things.

See also “include\_vars” for a module that makes this easy to accomodate into roles.

- include\_vars: “{{ ansible\_os\_family }}.yml”, etc.

---

<div class="post-metadata">

**Author:** ![Leibo](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Leibo](https://forum.ansible.com/u/Leibo)\
**Post date:** [July 13, 2014, 8:24pm UTC](https://forum.ansible.com/t/os-variables-variance/15660/3 "2014-07-13T20:24:49Z")

</div>

Thanks,  
by 'Non different' i meant as an example, tar command path is different between RedHat 7 and the rest but gunzip is the same. I need to use both on all roles.  
The files\_vars list will include the rhel 7 or the linux for the rest.  
so i need gunzip on both to get it into all roles...

---

<div class="post-metadata">

**Author:** ![Leibo](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Leibo](https://forum.ansible.com/u/Leibo)\
**Post date:** [July 14, 2014, 7:24am UTC](https://forum.ansible.com/t/os-variables-variance/15660/4 "2014-07-14T07:24:16Z")

</div>

Hi,

trying **include\_vars** I encounter an issue

Trying this inside a role task:

- include\_vars: “{{item}}”  
with\_first\_found:
- “vars/OS/{{ansible\_distribution}}\_{{ansible\_distribution\_major\_version}}.yml”
- “vars/OS/{{ansible\_distribution}}.yml”
- “vars/OS/{{ansible\_system}}.yml”

I get an error:

TASK: [app1 | include\_vars] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 ESTABLISH CONNECTION FOR USER: root  
failed: [linux1] =\> {“failed”: true, “item”: null}  
msg: No source file given

In my server I have **playbooks/vars/OS/Linux**.yml

Is there something wrong with my usage?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 14, 2014, 2:38pm UTC](https://forum.ansible.com/t/os-variables-variance/15660/5 "2014-07-14T14:38:27Z")

</div>

Seems like the intermediate directory “playbooks/” may be the problem.

---

<div class="post-metadata">

**Author:** ![Leibo](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Leibo](https://forum.ansible.com/u/Leibo)\
**Post date:** [July 14, 2014, 5:43pm UTC](https://forum.ansible.com/t/os-variables-variance/15660/6 "2014-07-14T17:43:44Z")

</div>

Didn’t help but I eventually got all Linux vars into a Linux.yml, all RedHat dependent or Suse into their own and more specific OS family with specific version into its own file.  
Created an empty vars file and used the list includes feature.

In the playbook I include:  
ansible\_system file  
than try [ansible\_os\_familly, empty.yml]  
than try [os family with major version , empty.yml]

Works great.

---

<div class="post-metadata">

**Author:** ![Pierre\_Bazoge](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@Pierre\_Bazoge](https://forum.ansible.com/u/Pierre_Bazoge)\
**Post date:** [February 25, 2016, 2:41pm UTC](https://forum.ansible.com/t/os-variables-variance/15660/7 "2016-02-25T14:41:19Z")

</div>

Adding “gather\_facts: true” in my playbook fixed the “No source file given” error.
