|
2 | 2 | - hosts: standalone |
3 | 3 | become: true |
4 | 4 | become_user: root |
5 | | - gather_facts: false |
| 5 | + gather_facts: true |
6 | 6 | vars_files: vars/defaults.yaml |
7 | 7 | roles: |
8 | 8 | - network_info |
|
108 | 108 | var: nmstate_ifs |
109 | 109 |
|
110 | 110 | - 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 |
112 | 112 | args: |
113 | 113 | stdin: "{{ network_state | to_nice_json }}" |
114 | 114 | vars: |
|
119 | 119 | config: "{{ nmstate_routes }}" |
120 | 120 | register: nmstateset |
121 | 121 |
|
| 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 | + |
122 | 140 | # Doing this in 2 steps means that we'll automatically rollback if we break |
123 | 141 | # networking such that ansible can no longer connect |
124 | 142 | - 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 }}" |
128 | 144 |
|
129 | 145 | # We have seen this creating a CentOS VM in OpenStack. We don't understand |
130 | 146 | # why they are created. Specifically we see a phantom ens3 device. It's |
|
0 commit comments