You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.5 KiB

  1. ---
  2. # Set 127.0.0.1 as fallback IP if we do not have host facts for host
  3. # ansible_default_ipv4 isn't what you think.
  4. # Thanks https://medium.com/opsops/ansible-default-ipv4-is-not-what-you-think-edb8ab154b10
  5. - name: Gather ansible_default_ipv4 from all hosts or specific hosts
  6. setup:
  7. gather_subset: '!all,network'
  8. filter: "ansible_default_ipv4"
  9. delegate_to: "{{ item }}"
  10. delegate_facts: true
  11. when: hostvars[item].ansible_default_ipv4 is not defined
  12. 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 }}"
  13. run_once: true
  14. ignore_unreachable: true
  15. tags: always
  16. - name: Create fallback_ips_base
  17. set_fact:
  18. fallback_ips_base: |
  19. ---
  20. {% 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 %}
  21. {% for item in search_hosts %}
  22. {% set found = hostvars[item].get('ansible_default_ipv4') %}
  23. {{ item }}: "{{ found.get('address', '127.0.0.1') }}"
  24. {% endfor %}
  25. delegate_to: localhost
  26. connection: local
  27. delegate_facts: true
  28. become: false
  29. run_once: true
  30. - name: Set fallback_ips
  31. set_fact:
  32. fallback_ips: "{{ hostvars.localhost.fallback_ips_base | from_yaml }}"