Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save halberom/72b70a8cba934b9d58b9 to your computer and use it in GitHub Desktop.

Select an option

Save halberom/72b70a8cba934b9d58b9 to your computer and use it in GitHub Desktop.

Revisions

  1. Gerard Lynch revised this gist Jul 1, 2015. 2 changed files with 8 additions and 3 deletions.
    6 changes: 5 additions & 1 deletion lookup.j2
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    {% for host in groups['gluster_servers'] %}
    {% if host != inventory_hostname %}
    - {{ hostvars[host]['ansible_' + gluster_interface]['ipv4']['address'] }}
    {% if 'ansible_' + rhel7_interface in hostvars[host] %}
    - {{ hostvars[host]['ansible_' + rhel7_interface]['ipv4']['address'] }}
    {% else %}
    - {{ hostvars[host]['ansible_' + default_interface]['ipv4']['address'] }}
    {% endif %}
    {% endif %}
    {% endfor %}
    5 changes: 3 additions & 2 deletions play.yml
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    ---
    - hosts: gluster_servers
    vars:
    gluster_interface: eth0
    rhel7_interface: enp0s3
    default_interface: eth0
    tasks:
    - set_fact:
    other_servers: "{{ lookup('template', 'lookup.j2') | from_yaml }}"

    - debug:
    msg: "addresses to use: {{ other_servers | join(',') }}
    msg: "addresses to use: {{ other_servers | join(',') }}"
  2. Gerard Lynch revised this gist Jul 1, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion lookup.j2
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    cluster_ips:
    {% for host in groups['gluster_servers'] %}
    {% if host != inventory_hostname %}
    - {{ hostvars[host]['ansible_' + gluster_interface]['ipv4']['address'] }}
  3. Gerard Lynch revised this gist Jul 1, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion lookup.j2
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    cluster_ips:
    {% for host in groups['gluster_servers'] %}
    {% if host != inventory_hostname %}
    - {{ hostvars[host]['ansible_' + gluster_interface]['ipv4']['address'] }}
    - {{ hostvars[host]['ansible_' + gluster_interface]['ipv4']['address'] }}
    {% endif %}
    {% endfor %}
  4. Gerard Lynch revised this gist Jul 1, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion play.yml
    Original file line number Diff line number Diff line change
    @@ -3,5 +3,8 @@
    vars:
    gluster_interface: eth0
    tasks:
    - set_fact:
    other_servers: "{{ lookup('template', 'lookup.j2') | from_yaml }}"

    - debug:
    msg: "addresses to use: {{ lookup('template', 'lookup.j2') | from_yaml }}
    msg: "addresses to use: {{ other_servers | join(',') }}
  5. Gerard Lynch revised this gist Jul 1, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lookup.j2
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    {% for host in groups['gluster_servers'] %}
    {% if host != inventory_hostname %}
    - {{ hostvars[host][gluster_interface]['ipv4']['address'] }}
    - {{ hostvars[host]['ansible_' + gluster_interface]['ipv4']['address'] }}
    {% endif %}
    {% endfor %}
  6. Gerard Lynch revised this gist Jul 1, 2015. 2 changed files with 7 additions and 9 deletions.
    5 changes: 3 additions & 2 deletions lookup.j2
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    {% for host in groups['gluster_servers'] %}
    - name: {{ host }}
    address: {{ hostvars[host][gluster_interface]['ipv4']['address'] }}
    {% if host != inventory_hostname %}
    - {{ hostvars[host][gluster_interface]['ipv4']['address'] }}
    {% endif %}
    {% endfor %}
    11 changes: 4 additions & 7 deletions play.yml
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,7 @@
    ---
    - hosts: gluster_servers
    vars:
    gluster_interface: eth0
    tasks:
    - set_fact:
    cluster_ips: "{{ lookup('template', 'lookup.j2') | from_yaml }}
    - debug:
    var: cluster_ips
    - debug:
    msg: "addresses to use: {{ lookup('template', 'lookup.j2') | from_yaml }}
  7. Gerard Lynch created this gist Jul 1, 2015.
    4 changes: 4 additions & 0 deletions lookup.j2
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    {% for host in groups['gluster_servers'] %}
    - name: {{ host }}
    address: {{ hostvars[host][gluster_interface]['ipv4']['address'] }}
    {% endfor %}
    10 changes: 10 additions & 0 deletions play.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    ---
    - hosts: gluster_servers
    tasks:
    - set_fact:
    cluster_ips: "{{ lookup('template', 'lookup.j2') | from_yaml }}
    - debug:
    var: cluster_ips