# Accessing group\_vars variables from a jinja2 loop

**URL:** <https://forum.ansible.com/t/accessing-group-vars-variables-from-a-jinja2-loop/25633>\
**Category:** Ansible Project\
**Created:** [September 29, 2017, 12:12am UTC](https://forum.ansible.com/t/accessing-group-vars-variables-from-a-jinja2-loop/25633 "2017-09-29T00:12:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alanpassel7](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@alanpassel7](https://forum.ansible.com/u/alanpassel7)\
**Post date:** [September 29, 2017, 12:12am UTC](https://forum.ansible.com/t/accessing-group-vars-variables-from-a-jinja2-loop/25633/1 "2017-09-29T00:12:07Z")

</div>

Good morning,

I’m trying to write a loop in a template that will access a variable from group\_vars. This variable is a string, with values separated by commas, so what I’d like to do is something like:

`  
{% for item in variable.split(‘,’) %)

- {{ item }}  
{% endfor %}  
`

with the group\_var being

`variable:"variable1,variable2,variable3..."`

But I have not been able to achieve this, nor has any cursory googling shown any examples of doing this. I have managed to find an example someone who wanted to do this, but ended up putting the variables into their inventory, but that’s not appropriate in this situation.

Is this possible, or do I need to find another solution?

Regards,

AP

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 29, 2017, 1:37am UTC](https://forum.ansible.com/t/accessing-group-vars-variables-from-a-jinja2-loop/25633/2 "2017-09-29T01:37:42Z")

</div>

it does not matter if it is a host var or group var, as long as it  
belongs to the host in your current task it should be directly  
available.
