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.

31 lines
1.1 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
  6. tags: always
  7. include_tasks: fallback_ips_gather.yml
  8. when: hostvars[delegate_host_to_gather_facts].ansible_default_ipv4 is not defined
  9. loop: "{{ groups['k8s_cluster']|default([]) + groups['etcd']|default([]) + groups['calico_rr']|default([]) }}"
  10. loop_control:
  11. loop_var: delegate_host_to_gather_facts
  12. run_once: yes
  13. - name: create fallback_ips_base
  14. set_fact:
  15. fallback_ips_base: |
  16. ---
  17. {% for item in (groups['k8s_cluster']|default([]) + groups['etcd']|default([]) + groups['calico_rr']|default([]))|unique %}
  18. {% set found = hostvars[item].get('ansible_default_ipv4') %}
  19. {{ item }}: "{{ found.get('address', '127.0.0.1') }}"
  20. {% endfor %}
  21. delegate_to: localhost
  22. connection: local
  23. delegate_facts: yes
  24. become: no
  25. run_once: yes
  26. - name: set fallback_ips
  27. set_fact:
  28. fallback_ips: "{{ hostvars.localhost.fallback_ips_base | from_yaml }}"