Skip to content

Commit ddb0807

Browse files
authored
Merge pull request #193 from shiftstack/nmstate
network: adjustments for new NetworkManager
2 parents 14e3158 + be58d7c commit ddb0807

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

playbooks/network.yaml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- hosts: standalone
33
become: true
44
become_user: root
5-
gather_facts: false
5+
gather_facts: true
66
vars_files: vars/defaults.yaml
77
roles:
88
- network_info
@@ -108,7 +108,7 @@
108108
var: nmstate_ifs
109109

110110
- name: Set nmstate # noqa no-changed-when
111-
ansible.builtin.command: nmstatectl set --no-commit --timeout 60
111+
ansible.builtin.command: nmstatectl apply --no-commit --timeout 60
112112
args:
113113
stdin: "{{ network_state | to_nice_json }}"
114114
vars:
@@ -119,12 +119,28 @@
119119
config: "{{ nmstate_routes }}"
120120
register: nmstateset
121121

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"
131+
ansible.builtin.set_fact:
132+
checkpoint: "{{ (nmstateset.stderr_lines | last).split()[-1] }}"
133+
134+
- name: Fail if the checkpoint has not been found or is incorrect
135+
when:
136+
- '"/org/freedesktop/NetworkManager/Checkpoint/" not in checkpoint'
137+
ansible.builtin.fail:
138+
msg: "nmstate checkpoint was not found or is incorrect: {{ checkpoint }}"
139+
122140
# Doing this in 2 steps means that we'll automatically rollback if we break
123141
# networking such that ansible can no longer connect
124142
- name: Commit the new network state # noqa no-changed-when
125-
ansible.builtin.command: nmstatectl commit "{{ checkpoint }}"
126-
vars:
127-
checkpoint: "{{ (nmstateset.stdout_lines | last).split()[1] }}"
143+
ansible.builtin.command: "nmstatectl commit {{ checkpoint }}"
128144

129145
# We have seen this creating a CentOS VM in OpenStack. We don't understand
130146
# why they are created. Specifically we see a phantom ens3 device. It's

0 commit comments

Comments
 (0)