Merge pull request #1138 from mattymo/idempotency-fixes
Idempotency fixes for etcd certs and resolvconf tasks
This commit is contained in:
commit
02fed4a082
3 changed files with 37 additions and 33 deletions
|
@ -61,7 +61,7 @@
|
||||||
{% if gen_node_certs[inventory_hostname] or
|
{% if gen_node_certs[inventory_hostname] or
|
||||||
(not etcdcert_node.results[0].stat.exists|default(False)) or
|
(not etcdcert_node.results[0].stat.exists|default(False)) or
|
||||||
(not etcdcert_node.results[1].stat.exists|default(False)) or
|
(not etcdcert_node.results[1].stat.exists|default(False)) or
|
||||||
(etcdcert_node.results[1].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcdcert_node.results[1].stat.path)|first|map(attribute="checksum")|default('')) -%}
|
(etcdcert_node.results[1].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcdcert_node.results[1].stat.path)|map(attribute="checksum")|first|default('')) -%}
|
||||||
{%- set _ = certs.update({'sync': True}) -%}
|
{%- set _ = certs.update({'sync': True}) -%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ certs.sync }}
|
{{ certs.sync }}
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
path: "{{ etcd_cert_dir }}"
|
path: "{{ etcd_cert_dir }}"
|
||||||
group: "{{ etcd_cert_group }}"
|
group: "{{ etcd_cert_group }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: root
|
owner: kube
|
||||||
|
mode: 0700
|
||||||
recurse: yes
|
recurse: yes
|
||||||
|
|
||||||
- name: "Gen_certs | create etcd script dir (on {{groups['etcd'][0]}})"
|
- name: "Gen_certs | create etcd script dir (on {{groups['etcd'][0]}})"
|
||||||
|
@ -12,6 +13,7 @@
|
||||||
path: "{{ etcd_script_dir }}"
|
path: "{{ etcd_script_dir }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: root
|
owner: root
|
||||||
|
mode: 0700
|
||||||
run_once: yes
|
run_once: yes
|
||||||
delegate_to: "{{groups['etcd'][0]}}"
|
delegate_to: "{{groups['etcd'][0]}}"
|
||||||
|
|
||||||
|
@ -20,8 +22,9 @@
|
||||||
path: "{{ etcd_cert_dir }}"
|
path: "{{ etcd_cert_dir }}"
|
||||||
group: "{{ etcd_cert_group }}"
|
group: "{{ etcd_cert_group }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: root
|
owner: kube
|
||||||
recurse: yes
|
recurse: yes
|
||||||
|
mode: 0700
|
||||||
run_once: yes
|
run_once: yes
|
||||||
delegate_to: "{{groups['etcd'][0]}}"
|
delegate_to: "{{groups['etcd'][0]}}"
|
||||||
|
|
||||||
|
@ -42,6 +45,7 @@
|
||||||
delegate_to: "{{groups['etcd'][0]}}"
|
delegate_to: "{{groups['etcd'][0]}}"
|
||||||
when: gen_certs|default(false)
|
when: gen_certs|default(false)
|
||||||
|
|
||||||
|
|
||||||
- name: Gen_certs | run cert generation script
|
- name: Gen_certs | run cert generation script
|
||||||
command: "bash -x {{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
|
command: "bash -x {{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
|
||||||
environment:
|
environment:
|
||||||
|
@ -114,7 +118,9 @@
|
||||||
- name: Gen_certs | Prepare tempfile for unpacking certs
|
- name: Gen_certs | Prepare tempfile for unpacking certs
|
||||||
shell: mktemp /tmp/certsXXXXX.tar.gz
|
shell: mktemp /tmp/certsXXXXX.tar.gz
|
||||||
register: cert_tempfile
|
register: cert_tempfile
|
||||||
|
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
|
||||||
|
inventory_hostname != groups['etcd'][0]
|
||||||
|
|
||||||
- name: Gen_certs | Write master certs to tempfile
|
- name: Gen_certs | Write master certs to tempfile
|
||||||
copy:
|
copy:
|
||||||
content: "{{etcd_master_cert_data.stdout}}"
|
content: "{{etcd_master_cert_data.stdout}}"
|
||||||
|
@ -154,13 +160,9 @@
|
||||||
group: "{{ etcd_cert_group }}"
|
group: "{{ etcd_cert_group }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: kube
|
owner: kube
|
||||||
|
mode: "u=rwX,g-rwx,o-rwx"
|
||||||
recurse: yes
|
recurse: yes
|
||||||
|
|
||||||
- name: Gen_certs | set permissions on keys
|
|
||||||
shell: chmod 0600 {{ etcd_cert_dir}}/*key.pem
|
|
||||||
when: inventory_hostname in groups['etcd']
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: Gen_certs | target ca-certificate store file
|
- name: Gen_certs | target ca-certificate store file
|
||||||
set_fact:
|
set_fact:
|
||||||
ca_cert_path: |-
|
ca_cert_path: |-
|
||||||
|
|
|
@ -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