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.

40 lines
1.5 KiB

  1. ---
  2. - name: Hosts | populate inventory into hosts file
  3. blockinfile:
  4. dest: /etc/hosts
  5. block: |-
  6. {% for item in (groups['k8s-cluster'] + groups['etcd'] + groups['calico-rr']|default([]))|unique -%}{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item]['ansible_default_ipv4']['address'])) }}{% if (item != hostvars[item]['ansible_hostname']) %} {{ hostvars[item]['ansible_hostname'] }} {{ hostvars[item]['ansible_hostname'] }}.{{ dns_domain }}{% endif %} {{ item }} {{ item }}.{{ dns_domain }}
  7. {% endfor %}
  8. state: present
  9. create: yes
  10. backup: yes
  11. marker: "# Ansible inventory hosts {mark}"
  12. when: populate_inventory_to_hosts_file
  13. - name: Hosts | populate kubernetes loadbalancer address into hosts file
  14. lineinfile:
  15. dest: /etc/hosts
  16. regexp: ".*{{ apiserver_loadbalancer_domain_name }}$"
  17. line: "{{ loadbalancer_apiserver.address }} {{ apiserver_loadbalancer_domain_name| default('lb-apiserver.kubernetes.local') }}"
  18. state: present
  19. backup: yes
  20. when:
  21. - loadbalancer_apiserver is defined
  22. - loadbalancer_apiserver.address is defined
  23. - apiserver_loadbalancer_domain_name is defined
  24. - name: Hosts | localhost ipv4 in hosts file
  25. lineinfile:
  26. dest: /etc/hosts
  27. line: "127.0.0.1 localhost localhost.localdomain"
  28. regexp: '^127.0.0.1.*$'
  29. state: present
  30. backup: yes
  31. - name: Hosts | localhost ipv6 in hosts file
  32. lineinfile:
  33. dest: /etc/hosts
  34. line: "::1 localhost6 localhost6.localdomain"
  35. regexp: '^::1.*$'
  36. state: present
  37. backup: yes