Skip to content
Snippets Groups Projects
Commit f6b72fa8 authored by Matthew Mosesohn's avatar Matthew Mosesohn
Browse files

Make resolvconf preinstall idempotent

parent 4c682951
No related branches found
No related tags found
No related merge requests found
...@@ -3,25 +3,16 @@ ...@@ -3,25 +3,16 @@
command: cp -f /etc/resolv.conf "{{ resolvconffile }}" command: cp -f /etc/resolv.conf "{{ resolvconffile }}"
when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
- name: Remove search/domain/nameserver options - name: Add domain/search/nameservers/options to resolv.conf
lineinfile:
dest: "{{item[0]}}"
state: absent
regexp: "^{{ item[1] }}.*$"
backup: yes
follow: yes
with_nested:
- "{{ [resolvconffile] + [base|default('')] + [head|default('')] }}"
- [ 'search ', 'nameserver ', 'domain ', 'options ' ]
notify: Preinstall | restart network
- name: Add domain/search/nameservers to resolv.conf
blockinfile: blockinfile:
dest: "{{resolvconffile}}" dest: "{{resolvconffile}}"
block: |- block: |-
{% for item in [domainentry] + [searchentries] + nameserverentries.split(',') -%} {% for item in [domainentry] + [searchentries] + nameserverentries.split(',') -%}
{{ item }} {{ item }}
{% endfor %} {% endfor %}
options ndots:{{ ndots }}
options timeout:2
options attempts:2
state: present state: present
insertbefore: BOF insertbefore: BOF
create: yes create: yes
...@@ -30,21 +21,32 @@ ...@@ -30,21 +21,32 @@
marker: "# Ansible entries {mark}" marker: "# Ansible entries {mark}"
notify: Preinstall | restart network notify: Preinstall | restart network
- name: Add options to resolv.conf - name: Remove search/domain/nameserver options before block
lineinfile: replace:
line: options {{ item }} dest: "{{item[0]}}"
dest: "{{resolvconffile}}" regexp: '^{{ item[1] }}[^#]*(?=# Ansible entries BEGIN)'
state: present
regexp: "^options.*{{ item }}$"
insertafter: EOF
backup: yes backup: yes
follow: yes follow: yes
with_items: with_nested:
- ndots:{{ ndots }} - "{{ [resolvconffile] + [base|default('')] + [head|default('')] }}"
- timeout:2 - [ 'search ', 'nameserver ', 'domain ', 'options ' ]
- attempts:2 when: item[0] != ""
notify: Preinstall | restart network notify: Preinstall | restart network
- name: Remove search/domain/nameserver options after block
replace:
dest: "{{item[0]}}"
regexp: '(# Ansible entries END\n(?:(?!^{{ item[1] }}).*\n)*)(?:^{{ item[1] }}.*\n?)+'
replace: '\1'
backup: yes
follow: yes
with_nested:
- "{{ [resolvconffile] + [base|default('')] + [head|default('')] }}"
- [ 'search ', 'nameserver ', 'domain ', 'options ' ]
when: item[0] != ""
notify: Preinstall | restart network
- name: get temporary resolveconf cloud init file content - name: get temporary resolveconf cloud init file content
command: cat {{ resolvconffile }} command: cat {{ resolvconffile }}
register: cloud_config register: cloud_config
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment