Make resolvconf preinstall idempotent
This commit is contained in:
parent
4c6829513c
commit
f6b72fa830
1 changed files with 26 additions and 24 deletions
|
@ -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 @@
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue