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.

62 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 ["CoreOS", "Container Linux by CoreOS"]
  5. - name: Add domain/search/nameservers/options to resolv.conf
  6. blockinfile:
  7. dest: "{{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. follow: yes
  20. marker: "# Ansible entries {mark}"
  21. notify: Preinstall | restart network
  22. - name: Remove search/domain/nameserver options before block
  23. replace:
  24. dest: "{{item[0]}}"
  25. regexp: '^{{ item[1] }}[^#]*(?=# Ansible entries BEGIN)'
  26. backup: yes
  27. follow: yes
  28. with_nested:
  29. - "{{ [resolvconffile] + [base|default('')] + [head|default('')] }}"
  30. - [ 'search ', 'nameserver ', 'domain ', 'options ' ]
  31. when: item[0] != ""
  32. notify: Preinstall | restart network
  33. - name: Remove search/domain/nameserver options after block
  34. replace:
  35. dest: "{{item[0]}}"
  36. regexp: '(# Ansible entries END\n(?:(?!^{{ item[1] }}).*\n)*)(?:^{{ item[1] }}.*\n?)+'
  37. replace: '\1'
  38. backup: yes
  39. follow: yes
  40. with_nested:
  41. - "{{ [resolvconffile] + [base|default('')] + [head|default('')] }}"
  42. - [ 'search ', 'nameserver ', 'domain ', 'options ' ]
  43. when: item[0] != ""
  44. notify: Preinstall | restart network
  45. - name: get temporary resolveconf cloud init file content
  46. command: cat {{ resolvconffile }}
  47. register: cloud_config
  48. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  49. - name: persist resolvconf cloud init file
  50. template:
  51. dest: "{{resolveconf_cloud_init_conf}}"
  52. src: resolvconf.j2
  53. owner: root
  54. mode: 0644
  55. notify: Preinstall | update resolvconf for Container Linux by CoreOS
  56. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]