Skip to content

Instantly share code, notes, and snippets.

@richm
Created February 11, 2021 01:00
Show Gist options
  • Save richm/0f6dd759a461705945eb5dd0c5287815 to your computer and use it in GitHub Desktop.
Save richm/0f6dd759a461705945eb5dd0c5287815 to your computer and use it in GitHub Desktop.
- hosts: localhost
vars:
nodenames: [node1, node2, node3]
tasks:
- name: add nodes
add_host:
name: "{{ item }}"
foo: bar
ha_cluster:
node_name: "{{ item ~ '-ha' }}"
when: item != 'node2'
loop: "{{ nodenames }}"
- name: add node2
add_host:
name: node2
foo: bar
- debug:
msg: ansible_play_hosts_all {{ ansible_play_hosts_all }} hostvars {{ ansible_play_hosts_all | map('extract', hostvars, ['ha_cluster', 'node_name']) | map('default', inventory_hostname) | list }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment