From db693d46df77db5c23f17ecf45d6daf0f387e594 Mon Sep 17 00:00:00 2001 From: eddebc Date: Fri, 20 Mar 2020 23:06:09 +0200 Subject: [PATCH] Fixed an issue where without a default GW, ansible_default_ipv4 would return an empty dict which passed as a valid fallback_ip dict item (#5394) --- roles/kubespray-defaults/defaults/main.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/roles/kubespray-defaults/defaults/main.yaml b/roles/kubespray-defaults/defaults/main.yaml index 04ae9f68f..15738165d 100644 --- a/roles/kubespray-defaults/defaults/main.yaml +++ b/roles/kubespray-defaults/defaults/main.yaml @@ -403,10 +403,13 @@ contiv_global_as: "65002" contiv_global_neighbor_as: "500" # Set 127.0.0.1 as fallback IP if we do not have host facts for host +# ansible_default_ipv4 isn't what you think. +# Thanks https://medium.com/opsops/ansible-default-ipv4-is-not-what-you-think-edb8ab154b10 fallback_ips_base: | --- {% for item in groups['k8s-cluster'] + groups['etcd'] + groups['calico-rr']|default([])|unique %} - {{ item }}: "{{ hostvars[item].get('ansible_default_ipv4', {'address': '127.0.0.1'})['address'] }}" + {% set found = hostvars[item].get('ansible_default_ipv4') %} + {{ item }}: "{{ found.get('address', '127.0.0.1') }}" {% endfor %} fallback_ips: "{{ fallback_ips_base | from_yaml }}"