Skip to content

Instantly share code, notes, and snippets.

@drybjed
Forked from halberom/lookup.j2
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drybjed/2bebf672e0f9255acf08 to your computer and use it in GitHub Desktop.
Save drybjed/2bebf672e0f9255acf08 to your computer and use it in GitHub Desktop.
{% for host in groups['gluster_servers'] %}
{% if host != inventory_hostname %}
{% 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 %}
---
- hosts: gluster_servers
vars:
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(',') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment