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.

60 lines
1.9 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('')] | difference(['']) }}"
  30. - [ 'search ', 'nameserver ', 'domain ', 'options ' ]
  31. notify: Preinstall | restart network
  32. - name: Remove search/domain/nameserver options after block
  33. replace:
  34. dest: "{{item[0]}}"
  35. regexp: '(# Ansible entries END\n(?:(?!^{{ item[1] }}).*\n)*)(?:^{{ item[1] }}.*\n?)+'
  36. replace: '\1'
  37. backup: yes
  38. follow: yes
  39. with_nested:
  40. - "{{ [resolvconffile, base|default(''), head|default('')] | difference(['']) }}"
  41. - [ 'search ', 'nameserver ', 'domain ', 'options ' ]
  42. notify: Preinstall | restart network
  43. - name: get temporary resolveconf cloud init file content
  44. command: cat {{ resolvconffile }}
  45. register: cloud_config
  46. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  47. - name: persist resolvconf cloud init file
  48. template:
  49. dest: "{{resolveconf_cloud_init_conf}}"
  50. src: resolvconf.j2
  51. owner: root
  52. mode: 0644
  53. notify: Preinstall | update resolvconf for Container Linux by CoreOS
  54. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]