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.

34 lines
1.2 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. setup:
  7. gather_subset: '!all,network'
  8. filter: "ansible_default_ipv4"
  9. delegate_to: "{{ item }}"
  10. delegate_facts: yes
  11. when: hostvars[item].ansible_default_ipv4 is not defined
  12. loop: "{{ (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique }}"
  13. run_once: yes
  14. ignore_unreachable: true
  15. tags: always
  16. - name: Create fallback_ips_base
  17. set_fact:
  18. fallback_ips_base: |
  19. ---
  20. {% for item in (groups['k8s_cluster'] | default([]) + groups['etcd'] | default([]) + groups['calico_rr'] | default([])) | unique %}
  21. {% set found = hostvars[item].get('ansible_default_ipv4') %}
  22. {{ item }}: "{{ found.get('address', '127.0.0.1') }}"
  23. {% endfor %}
  24. delegate_to: localhost
  25. connection: local
  26. delegate_facts: yes
  27. become: no
  28. run_once: yes
  29. - name: Set fallback_ips
  30. set_fact:
  31. fallback_ips: "{{ hostvars.localhost.fallback_ips_base | from_yaml }}"