Created
February 11, 2021 01:00
-
-
Save richm/0f6dd759a461705945eb5dd0c5287815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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