|
45 | 45 | debug: |
46 | 46 | var: network_provider |
47 | 47 |
|
48 | | - # FIXME: assert profile present |
49 | | - # FIXME: assert profile/device up + IP address |
| 48 | + - name: Get NM connection file |
| 49 | + slurp: |
| 50 | + src: "/etc/NetworkManager/system-connections/{{ interface }}.nmconnection" |
| 51 | + register: nm_connection_file |
| 52 | + when: |
| 53 | + - network_provider == 'nm' |
| 54 | + # RHEL up to 8 uses initscripts backend |
| 55 | + - ansible_distribution_major_version | int >= 9 |
| 56 | + |
| 57 | + - name: Assert settings in NM connection file |
| 58 | + assert: |
| 59 | + that: |
| 60 | + - "('interface-name=' + interface) in nm_connection_file.content | b64decode" |
| 61 | + - "'type=ethernet' in nm_connection_file.content | b64decode" |
| 62 | + - "'address1=192.0.2.1/24' in nm_connection_file.content | b64decode" |
| 63 | + - "'method=manual' in nm_connection_file.content | b64decode" |
| 64 | + when: |
| 65 | + - network_provider == 'nm' |
| 66 | + # RHEL up to 8 uses initscripts backend |
| 67 | + - ansible_distribution_major_version | int >= 9 |
| 68 | + |
| 69 | + - name: Get NM connection status |
| 70 | + command: "nmcli connection show {{ interface }}" |
| 71 | + changed_when: false |
| 72 | + register: nm_connection_status |
| 73 | + when: network_provider == 'nm' |
| 74 | + |
| 75 | + - name: Assert NM connection status |
| 76 | + assert: |
| 77 | + that: |
| 78 | + - nm_connection_status.stdout is search("ipv4.addresses:\s+192.0.2.1/24") |
| 79 | + when: network_provider == 'nm' |
| 80 | + |
| 81 | + - name: Get initscripts connection file |
| 82 | + slurp: |
| 83 | + src: "/etc/sysconfig/network-scripts/ifcfg-{{ interface }}" |
| 84 | + register: initscripts_connection_file |
| 85 | + when: network_provider == 'initscripts' or ansible_distribution_major_version | int < 9 |
| 86 | + |
| 87 | + - name: Assert settings in initscripts connection file |
| 88 | + assert: |
| 89 | + that: |
| 90 | + - "'TYPE=Ethernet' in initscripts_connection_file.content | b64decode" |
| 91 | + - "'DEVICE={{ interface }}' in initscripts_connection_file.content | b64decode" |
| 92 | + - "'IPADDR=192.0.2.1' in initscripts_connection_file.content | b64decode" |
| 93 | + - "'PREFIX=24' in initscripts_connection_file.content | b64decode" |
| 94 | + when: network_provider == 'initscripts' or ansible_distribution_major_version | int < 9 |
| 95 | + |
50 | 96 | - name: Include the tasks 'down_profile+delete_interface.yml' |
51 | 97 | include_tasks: tasks/down_profile+delete_interface.yml |
52 | 98 | vars: |
|
0 commit comments