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.4 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 }}"
  18. state: present
  19. backup: yes
  20. when:
  21. - loadbalancer_apiserver is defined
  22. - loadbalancer_apiserver.address 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