Skip to content

Commit fbf7d1c

Browse files
authored
Merge pull request #243 from shiftstack/idempotency
Make playbook idempotent
2 parents 9e10782 + 46d6a07 commit fbf7d1c

2 files changed

Lines changed: 60 additions & 28 deletions

File tree

playbooks/install_stack.yaml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
- /opt/exported-data/extra-host-file-entries.json
6363
- /opt/exported-data/all-nodes-extra-map-data.json
6464

65+
- name: Check if TripleO has already been deployed
66+
ansible.builtin.stat:
67+
path: /etc/openstack/clouds.yaml
68+
register: tripleo_deployed
69+
become: true
70+
become_user: root
71+
6572
- name: Enable SSL
6673
when: ssl_enabled
6774
block:
@@ -75,7 +82,9 @@
7582
- /usr/share/openstack-tripleo-heat-templates/environments/ssl/inject-trust-anchor.yaml
7683

7784
- name: Generate SSL self-signed certificate on localhost
78-
when: ssl_enabled
85+
when:
86+
- ssl_enabled
87+
- not tripleo_deployed.stat.exists
7988
become: false
8089
# We run this block on localhost because we don't want to put the CA key on the remote
8190
# server, which could lead to security problems.
@@ -96,7 +105,9 @@
96105
cert_name: standalone
97106

98107
- name: Prepare the host for SSL
99-
when: ssl_enabled
108+
when:
109+
- ssl_enabled
110+
- not tripleo_deployed.stat.exists
100111
no_log: true
101112
block:
102113
- name: Read and clean SSL files
@@ -307,6 +318,7 @@
307318
neutron_bridge_mappings: "{{ base_bridge_mappings }}"
308319

309320
- name: Create standalone_parameters.yaml
321+
when: not tripleo_deployed.stat.exists
310322
no_log: true
311323
ansible.builtin.template:
312324
mode: '644'
@@ -506,7 +518,42 @@
506518
when:
507519
- ceph_enabled
508520

521+
- name: Clean up stale heat processes from previous deploy
522+
become: true
523+
become_user: root
524+
when: not tripleo_deployed.stat.exists
525+
block:
526+
- name: Check if heat-all is already running (previous deploy with --keep-running)
527+
ansible.builtin.command: pgrep -f heat-all
528+
register: heat_running
529+
failed_when: false
530+
changed_when: false
531+
532+
- name: Kill stale heat-all processes
533+
# Each tripleo deploy forks a new heat-all without killing old ones.
534+
# Multiple heat-all processes sharing port 8006 via SO_REUSEPORT
535+
# causes API requests to be randomly routed to the wrong instance,
536+
# resulting in 'Stack create failed'.
537+
ansible.builtin.command: pkill -9 -f heat-all
538+
changed_when: true
539+
when: heat_running.rc == 0
540+
541+
- name: Wait for heat processes to terminate
542+
ansible.builtin.command: pgrep -f heat-all
543+
register: heat_check
544+
failed_when: false
545+
changed_when: false
546+
retries: 10
547+
delay: 1
548+
until: heat_check.rc != 0
549+
550+
- name: Remove stack update mark to ensure a clean stack create
551+
ansible.builtin.file:
552+
path: /var/lib/tripleo-heat-installer/update_mark_standalone
553+
state: absent
554+
509555
- name: Run TripleO deploy
556+
when: not tripleo_deployed.stat.exists
510557
ansible.builtin.import_role:
511558
name: tripleo.operator.tripleo_deploy
512559
vars:

playbooks/network.yaml

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,6 @@
6767
ipv6:
6868
enabled: false
6969
70-
# this saves the static route configuration including the default route
71-
# prior to filtering later
72-
73-
- name: Save route info # noqa no-changed-when
74-
ansible.builtin.command: nmstatectl show --json
75-
register: pre
76-
77-
- name: Create fact for nmstate_routes
78-
ansible.builtin.set_fact:
79-
nmstate_routes: "{{ pre.stdout | from_json | json_query(q) }}"
80-
vars:
81-
q: "routes.config"
82-
8370
# This works round a TripleO installation failure caused by NM-managed
8471
# interfaces 'failing' because:
8572
# * The default NM configuration specifies DHCP
@@ -112,24 +99,22 @@
11299
args:
113100
stdin: "{{ network_state | to_nice_json }}"
114101
vars:
102+
# Do not include routes in the desired state. nmstatectl apply
103+
# without a routes section leaves existing routes untouched.
104+
# Previously we captured and replayed routes, but on re-run
105+
# (idempotency) the captured routes reference interfaces that
106+
# nmstate cannot manage (e.g. eno1 enslaved to br-ex, or
107+
# br-hostonly which nmstate considers an unsupported tun type),
108+
# causing VerificationError failures.
115109
network_state:
116110
interfaces: "{{ nmstate_ifs }}"
117-
# add saved static routes
118-
routes:
119-
config: "{{ nmstate_routes }}"
120111
register: nmstateset
121112

122-
- name: Set fact for nmstate checkpoing on RHEL8
123-
when:
124-
- ansible_facts.distribution_major_version == "8"
125-
ansible.builtin.set_fact:
126-
checkpoint: "{{ (nmstateset.stdout_lines | last).split()[1] }}"
127-
128-
- name: Set fact for nmstate checkpoing on RHEL9
129-
when:
130-
- ansible_facts.distribution_major_version == "9"
113+
- name: Extract nmstate checkpoint from output
131114
ansible.builtin.set_fact:
132-
checkpoint: "{{ (nmstateset.stderr_lines | last).split()[-1] }}"
115+
checkpoint: >-
116+
{{ (nmstateset.stdout + nmstateset.stderr)
117+
| regex_search('/org/freedesktop/NetworkManager/Checkpoint/\d+') }}
133118
134119
- name: Fail if the checkpoint has not been found or is incorrect
135120
when:

0 commit comments

Comments
 (0)