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.

59 lines
2.0 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 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] + nameserverentries.split(',') -%}
  10. {{ item }}
  11. {% endfor %}
  12. options ndots:{{ ndots }}
  13. options timeout:2
  14. options attempts:2
  15. state: present
  16. insertbefore: BOF
  17. create: yes
  18. backup: yes
  19. marker: "# Ansible entries {mark}"
  20. notify: Preinstall | propagate resolvconf to k8s components
  21. - name: Remove search/domain/nameserver options before block
  22. replace:
  23. dest: "{{ item[0] }}"
  24. regexp: '^{{ item[1] }}[^#]*(?=# Ansible entries BEGIN)'
  25. backup: yes
  26. follow: yes
  27. with_nested:
  28. - "{{ [resolvconffile, base|default(''), head|default('')] | difference(['']) }}"
  29. - [ 'search ', 'nameserver ', 'domain ', 'options ' ]
  30. notify: Preinstall | propagate resolvconf to k8s components
  31. - name: Remove search/domain/nameserver options after block
  32. replace:
  33. dest: "{{ item[0] }}"
  34. regexp: '(# Ansible entries END\n(?:(?!^{{ item[1] }}).*\n)*)(?:^{{ item[1] }}.*\n?)+'
  35. replace: '\1'
  36. backup: yes
  37. follow: yes
  38. with_nested:
  39. - "{{ [resolvconffile, base|default(''), head|default('')] | difference(['']) }}"
  40. - [ 'search ', 'nameserver ', 'domain ', 'options ' ]
  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 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 Container Linux by Kinvolk"]