Dynamic GlusterFS Configuration (Looping)

6 views
Skip to first unread message

Shaun Dolan

unread,
Jan 22, 2018, 10:35:25 AM1/22/18
to Ansible Project
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

Shaun Dolan

unread,
Jan 22, 2018, 10:53:25 AM1/22/18
to Ansible Project
More simply put, I'm trying to iterate over the "cluster:" key values and not the "gluster_volume".

Kai Stian Olstad

unread,
Jan 22, 2018, 11:18:50 AM1/22/18
to ansible...@googlegroups.com
On Monday, 22 January 2018 16.35.25 CET Shaun Dolan wrote:
> 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 %}

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


--
Kai Stian Olstad

Shaun Dolan

unread,
Jan 22, 2018, 12:30:29 PM1/22/18
to Ansible Project
Thank you Kai.  Someone around the office just provided me the filter to_json... that was the missing link.  Appreciate your prompt response.

Shaun Dolan

unread,
Jan 22, 2018, 12:32:14 PM1/22/18
to Ansible Project
I don't believe IP was required, my gluster volume is working with dns name entries from play_hosts.
"{{ play_hosts | to_json }}"
Reply all
Reply to author
Forward
0 new messages