# How do I assign different variable values for different group system

**URL:** <https://forum.ansible.com/t/how-do-i-assign-different-variable-values-for-different-group-system/31815>\
**Category:** Ansible Project\
**Created:** [December 12, 2019, 9:15pm UTC](https://forum.ansible.com/t/how-do-i-assign-different-variable-values-for-different-group-system/31815 "2019-12-12T21:15:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xinhuan\_Zheng](https://avatars.discourse-cdn.com/v4/letter/x/a88e57/32.png) [@Xinhuan\_Zheng](https://forum.ansible.com/u/Xinhuan_Zheng)\
**Post date:** [December 12, 2019, 9:15pm UTC](https://forum.ansible.com/t/how-do-i-assign-different-variable-values-for-different-group-system/31815/1 "2019-12-12T21:15:28Z")

</div>

Hello,

I’m trying to create an Ansible role, networking, to automate /etc/resolv.conf file. I created this role like below:

production

networking.yml

group\_vars/  
agroup  
bgroup

roles/  
networking/  
tasks/main.yml  
templates/resolv.conf.j2

In my resolv.conf.j2 file, I put variables in this file:

{% for item in nameserver %}  
nameserver {{ item }}  
{% endfor %}

The name servers will be different for different group systems.

In group\_vars/agroup:

---

<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:** [December 13, 2019, 12:05am UTC](https://forum.ansible.com/t/how-do-i-assign-different-variable-values-for-different-group-system/31815/2 "2019-12-13T00:05:43Z")

</div>

Why don't you just run the code and check for yourself?  
Anyway, the answer to your question is yes.
