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.

39 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. - name: Hosts | populate kubernetes loadbalancer address into hosts file
  13. lineinfile:
  14. dest: /etc/hosts
  15. regexp: ".*{{ apiserver_loadbalancer_domain_name }}$"
  16. line: "{{ loadbalancer_apiserver.address }} {{ apiserver_loadbalancer_domain_name| default('lb-apiserver.kubernetes.local') }}"
  17. state: present
  18. backup: yes
  19. when:
  20. - loadbalancer_apiserver is defined
  21. - loadbalancer_apiserver.address is defined
  22. - apiserver_loadbalancer_domain_name is defined
  23. - name: Hosts | localhost ipv4 in hosts file
  24. lineinfile:
  25. dest: /etc/hosts
  26. line: "127.0.0.1 localhost localhost.localdomain"
  27. regexp: '^127.0.0.1.*$'
  28. state: present
  29. backup: yes
  30. - name: Hosts | localhost ipv6 in hosts file
  31. lineinfile:
  32. dest: /etc/hosts
  33. line: "::1 localhost6 localhost6.localdomain"
  34. regexp: '^::1.*$'
  35. state: present
  36. backup: yes