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.

37 lines
1.3 KiB

  1. ---
  2. - name: Hosts | populate inventory into hosts file
  3. blockinfile:
  4. dest: /etc/hosts
  5. block: |-
  6. {% for item in groups['all'] -%}
  7. {{ 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'] }}{% endif %} {{ item }}
  8. {% endfor %}
  9. state: present
  10. create: yes
  11. backup: yes
  12. marker: "# Ansible inventory hosts {mark}"
  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: loadbalancer_apiserver is defined and apiserver_loadbalancer_domain_name is defined
  21. - name: Hosts | localhost ipv4 in hosts file
  22. lineinfile:
  23. dest: /etc/hosts
  24. line: "127.0.0.1 localhost localhost.localdomain"
  25. regexp: '^127.0.0.1.*$'
  26. state: present
  27. backup: yes
  28. - name: Hosts | localhost ipv6 in hosts file
  29. lineinfile:
  30. dest: /etc/hosts
  31. line: "::1 localhost6 localhost6.localdomain"
  32. regexp: '^::1.*$'
  33. state: present
  34. backup: yes