From c73ebba5b6cfb09887e9fdb6b244e3f42057136d Mon Sep 17 00:00:00 2001 From: AndrewPaglusch Date: Sat, 15 Jun 2024 13:59:40 -0500 Subject: [PATCH] check for duplicate ips on startup --- tasks/main.yml | 5 ++++- tasks/preflight.yml | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tasks/preflight.yml 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