# Dynamic GlusterFS Configuration (Looping)

**URL:** <https://forum.ansible.com/t/dynamic-glusterfs-configuration-looping/26529>\
**Category:** Ansible Project\
**Created:** [January 22, 2018, 3:35pm UTC](https://forum.ansible.com/t/dynamic-glusterfs-configuration-looping/26529 "2018-01-22T15:35:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaun\_Dolan](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shaun\_Dolan](https://forum.ansible.com/u/Shaun_Dolan)\
**Post date:** [January 22, 2018, 3:35pm UTC](https://forum.ansible.com/t/dynamic-glusterfs-configuration-looping/26529/1 "2018-01-22T15:35:25Z")

</div>

All,

I’m trying to loop over play\_hosts to build out my cluster in a glusterfs configuration ansible/ruby block. I’m not sure of the best way to do this, but would like any feedback you can provide.  
I didn’t believe with\_items would work in this situation, because I’m trying to inject x number of unknown items to build a glusterfs cluster. The items are determined from the current inventory/playlist, I’m trying to avoid changing inventory files unless absolutely required.

Here is what I’ve tried (am I headed down the right path?):

`

- name: create gluster volume  
gluster\_volume:  
state: present  
name: gluster0  
bricks: /bricks/brick1/g1  
rebalance: yes  
replicas: yes  
cluster: |  
{% for host in play\_hosts %}  
“- {{hostvars[host].ansible\_default\_ipv4.address}}”  
{% endfor %}  
run\_once: true  
sudo: yes

`

Thanks,

Shaun

---

<div class="post-metadata">

**Author:** ![Shaun\_Dolan](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shaun\_Dolan](https://forum.ansible.com/u/Shaun_Dolan)\
**Post date:** [January 22, 2018, 3:53pm UTC](https://forum.ansible.com/t/dynamic-glusterfs-configuration-looping/26529/2 "2018-01-22T15:53:25Z")

</div>

More simply put, I’m trying to iterate over the “cluster:” key values and not the “gluster\_volume”.

---

<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:** [January 22, 2018, 4:18pm UTC](https://forum.ansible.com/t/dynamic-glusterfs-configuration-looping/26529/3 "2018-01-22T16:18:20Z")

</div>

Since cluster takes a list try this  
&nbsp;&nbsp;cluster: "{{ play\_hosts | map('extract', hostvars, 'ansible\_default\_ipv4.address') | list }}"

---

<div class="post-metadata">

**Author:** ![Shaun\_Dolan](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shaun\_Dolan](https://forum.ansible.com/u/Shaun_Dolan)\
**Post date:** [January 22, 2018, 5:30pm UTC](https://forum.ansible.com/t/dynamic-glusterfs-configuration-looping/26529/4 "2018-01-22T17:30:29Z")

</div>

Thank you Kai. Someone around the office just provided me the filter to\_json… that was the missing link. Appreciate your prompt response.

---

<div class="post-metadata">

**Author:** ![Shaun\_Dolan](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shaun\_Dolan](https://forum.ansible.com/u/Shaun_Dolan)\
**Post date:** [January 22, 2018, 5:32pm UTC](https://forum.ansible.com/t/dynamic-glusterfs-configuration-looping/26529/5 "2018-01-22T17:32:14Z")

</div>

I don’t believe IP was required, my gluster volume is working with dns name entries from play\_hosts.  
“{{ play\_hosts | to\_json }}”
