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.

58 lines
2.2 KiB

  1. ---
  2. - name: Create temporary resolveconf cloud init file
  3. command: cp -f /etc/resolv.conf "{{ resolvconffile }}"
  4. when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
  5. - name: Add domain/search/nameservers/options to resolv.conf
  6. blockinfile:
  7. path: "{{ resolvconffile }}"
  8. block: |-
  9. {% for item in [domainentry] + [searchentries] -%}
  10. {{ item }}
  11. {% endfor %}
  12. {% for item in nameserverentries.split(',') %}
  13. nameserver {{ item }}
  14. {% endfor %}
  15. options ndots:{{ ndots }} timeout:{{ dns_timeout | default('2') }} attempts:{{ dns_attempts | default('2') }}
  16. state: present
  17. insertbefore: BOF
  18. create: true
  19. backup: "{{ not resolvconf_stat.stat.islnk }}"
  20. marker: "# Ansible entries {mark}"
  21. mode: "0644"
  22. notify: Preinstall | propagate resolvconf to k8s components
  23. - name: Remove search/domain/nameserver options before block
  24. replace:
  25. path: "{{ item[0] }}"
  26. regexp: '^{{ item[1] }}[^#]*(?=# Ansible entries BEGIN)'
  27. backup: "{{ not resolvconf_stat.stat.islnk }}"
  28. with_nested:
  29. - "{{ [resolvconffile, base | default(''), head | default('')] | difference(['']) }}"
  30. - [ 'search\s', 'nameserver\s', 'domain\s', 'options\s' ]
  31. notify: Preinstall | propagate resolvconf to k8s components
  32. - name: Remove search/domain/nameserver options after block
  33. replace:
  34. path: "{{ item[0] }}"
  35. regexp: '(# Ansible entries END\n(?:(?!^{{ item[1] }}).*\n)*)(?:^{{ item[1] }}.*\n?)+'
  36. replace: '\1'
  37. backup: "{{ not resolvconf_stat.stat.islnk }}"
  38. with_nested:
  39. - "{{ [resolvconffile, base | default(''), head | default('')] | difference(['']) }}"
  40. - [ 'search\s', 'nameserver\s', 'domain\s', 'options\s' ]
  41. notify: Preinstall | propagate resolvconf to k8s components
  42. - name: Get temporary resolveconf cloud init file content
  43. command: cat {{ resolvconffile }}
  44. register: cloud_config
  45. when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
  46. - name: Persist resolvconf cloud init file
  47. template:
  48. dest: "{{ resolveconf_cloud_init_conf }}"
  49. src: resolvconf.j2
  50. owner: root
  51. mode: "0644"
  52. notify: Preinstall | update resolvconf for Flatcar Container Linux by Kinvolk
  53. when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]