# How to add os based variables into group\_vars

**URL:** <https://forum.ansible.com/t/how-to-add-os-based-variables-into-group-vars/26610>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 31, 2018, 4:43am UTC](https://forum.ansible.com/t/how-to-add-os-based-variables-into-group-vars/26610 "2018-01-31T04:43:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriman\_dharba](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sriman\_dharba](https://forum.ansible.com/u/sriman_dharba)\
**Post date:** [January 31, 2018, 4:43am UTC](https://forum.ansible.com/t/how-to-add-os-based-variables-into-group-vars/26610/1 "2018-01-31T04:43:36Z")

</div>

Hello,

I wanted to manage repo names from group\_vars based on OS type. I have a requirement to set reponames for different OS & versions like Centos/Redhat/Ubuntu with all stable versions. The goal is to manage future repo names from group\_vars

My variables looks like this

group\_vars/all.yml

---

<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:** [February 1, 2018, 7:22pm UTC](https://forum.ansible.com/t/how-to-add-os-based-variables-into-group-vars/26610/2 "2018-02-01T19:22:25Z")

</div>

- name: 'Upgrading packages to latest'  
&nbsp;&nbsp;yum:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "\*"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: latest  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enablerepo: "{{ vars[repo\_name] }}"  
&nbsp;&nbsp;when: ansible\_distribution == "RedHat" or ansible\_\_distribution == "CentOS"

or just drop the set\_fact and use

- name: 'Upgrading packages to latest'  
&nbsp;&nbsp;yum:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "\*"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: latest  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enablerepo: "{{ vars['repo\_' ~ ansible\_distribution\_major\_version ~ '\_repo'] }}"  
&nbsp;&nbsp;when: ansible\_distribution == "RedHat" or ansible\_\_distribution == "CentOS"

---

<div class="post-metadata">

**Author:** ![sriman\_dharba](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sriman\_dharba](https://forum.ansible.com/u/sriman_dharba)\
**Post date:** [February 2, 2018, 6:51am UTC](https://forum.ansible.com/t/how-to-add-os-based-variables-into-group-vars/26610/3 "2018-02-02T06:51:36Z")

</div>

Thanks Kai! Came across vars & hostvars from FAQ section of ansible. Missed it, thanks for the response.

Regards  
Sri
