--- # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 - debug: msg: "{{ extra_vars_to_add_to_hosts }}" - name: Check if primary host is already on list set_fact: primary_registered="{{ extra_vars_to_add_to_hosts | selectattr('private_ip', 'equalto', GLOBAL_PRIMARY_IP) | list }}" when: extra_vars_to_add_to_hosts is defined - debug: msg: "{{ primary_registered }}" - name: Add primary host IP to list set_fact: extra_vars_to_add_to_hosts: "{{ (extra_vars_to_add_to_hosts | default([])) + [{'private_ip': GLOBAL_PRIMARY_IP, 'hostname': GLOBAL_INPUT_HOSTNAME}] }}" when: primary_registered is undefined or primary_registered | length == 0 - debug: msg: "{{ extra_vars_to_add_to_hosts }}" - name: Check if secondary host is already on list set_fact: secondary_registered="{{ extra_vars_to_add_to_hosts | selectattr('private_ip', 'equalto', item) | list }}" when: extra_vars_to_add_to_hosts is defined and GLOBAL_NODE_IPS_LIST is defined with_items: GLOBAL_NODE_IPS_LIST - debug: msg: "{{ secondary_registered }}" - name: Add nodes hosts to list set_fact: extra_vars_to_add_to_hosts: "{{ (extra_vars_to_add_to_hosts | default([])) + [{'private_ip': item, 'hostname': GLOBAL_INPUT_HOSTNAME+((ansible_loop.index+1) | string) }] }}" when: - GLOBAL_NODE_IPS is defined - GLOBAL_NODE_IPS_LIST is defined - secondary_registered is undefined or secondary_registered | length == 0 loop: "{{ GLOBAL_NODE_IPS_LIST }}" loop_control: extended: yes - debug: msg: "{{ extra_vars_to_add_to_hosts }}" - name: Set global variable with hosts and ip list set_fact: GLOBAL_HOSTS_LIST="{{ extra_vars_to_add_to_hosts }}" - debug: msg: "{{ GLOBAL_HOSTS_LIST }}"