diff --git a/tasks/main.yml b/tasks/main.yml index 585e37d..29b982f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,7 +4,10 @@ - name: Uninstall Nebula (clean install) include_tasks: uninstall.yml when: nebula_clean_install|bool - + + - name: Preflight checks + include_tasks: preflight.yml + - name: Install Nebula on all hosts include_tasks: nebula.yml diff --git a/tasks/preflight.yml b/tasks/preflight.yml new file mode 100644 index 0000000..8a26ff0 --- /dev/null +++ b/tasks/preflight.yml @@ -0,0 +1,22 @@ +--- +- name: Preflight checks + block: + - name: Collecting all nebula_internal_ip_addr values + set_fact: + sorted_ips: "{{ hostvars | map('extract', hostvars, ['nebula_internal_ip_addr']) | list | sort }}" + + - name: Initialize duplicated_ips list + set_fact: + duplicated_ips: [] + + - name: Looking for duplicate IP addresses + set_fact: + duplicated_ips: "{{ duplicated_ips + [item] }}" + loop: "{{ sorted_ips | unique }}" + when: "sorted_ips | select('equalto', item) | list | length > 1" + + - name: Fail if duplicate IP addresses are found + fail: + msg: "You have one or more hosts with duplicate IP addresses assigned: {{ duplicated_ips }}" + when: duplicated_ips | length > 0 + run_once: true