2020-04-16 22:22:47 +08:00
|
|
|
---
|
|
|
|
# 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
|
|
|
|
|
2024-07-26 10:17:48 +08:00
|
|
|
- name: Gather ansible_default_ipv4 from all hosts or specific hosts
|
2023-01-06 03:59:58 +08:00
|
|
|
setup:
|
|
|
|
gather_subset: '!all,network'
|
|
|
|
filter: "ansible_default_ipv4"
|
|
|
|
delegate_to: "{{ item }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
delegate_facts: true
|
2023-01-06 03:59:58 +08:00
|
|
|
when: hostvars[item].ansible_default_ipv4 is not defined
|
2024-07-26 10:17:48 +08:00
|
|
|
loop: "{{ (ansible_play_hosts_all + [groups['kube_control_plane'][0]]) | unique if ansible_limit is defined else (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique }}"
|
2024-08-28 13:30:56 +08:00
|
|
|
run_once: true
|
2023-11-11 04:07:18 +08:00
|
|
|
ignore_unreachable: true
|
2023-01-06 03:59:58 +08:00
|
|
|
tags: always
|
2020-04-16 22:22:47 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Create fallback_ips_base
|
2020-04-16 22:22:47 +08:00
|
|
|
set_fact:
|
|
|
|
fallback_ips_base: |
|
|
|
|
---
|
2024-07-26 10:17:48 +08:00
|
|
|
{% set search_hosts = (ansible_play_hosts_all + [groups['kube_control_plane'][0]]) | unique if ansible_limit is defined else (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique %}
|
|
|
|
{% for item in search_hosts %}
|
2020-04-16 22:22:47 +08:00
|
|
|
{% set found = hostvars[item].get('ansible_default_ipv4') %}
|
|
|
|
{{ item }}: "{{ found.get('address', '127.0.0.1') }}"
|
|
|
|
{% endfor %}
|
|
|
|
delegate_to: localhost
|
2020-06-25 23:14:38 +08:00
|
|
|
connection: local
|
2024-08-28 13:30:56 +08:00
|
|
|
delegate_facts: true
|
|
|
|
become: false
|
|
|
|
run_once: true
|
2020-04-16 22:22:47 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Set fallback_ips
|
2020-04-16 22:22:47 +08:00
|
|
|
set_fact:
|
|
|
|
fallback_ips: "{{ hostvars.localhost.fallback_ips_base | from_yaml }}"
|