Dynamic GlusterFS Configuration (Looping)

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

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

Since cluster takes a list try this
  cluster: "{{ play_hosts | map('extract', hostvars, 'ansible_default_ipv4.address') | list }}"

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

I don’t believe IP was required, my gluster volume is working with dns name entries from play_hosts.
“{{ play_hosts | to_json }}”