|
18 | 18 | - name: Converge |
19 | 19 | hosts: all |
20 | 20 | tasks: |
21 | | - - name: Include config_drive role |
| 21 | + - name: Include config_drive role with full configuration |
22 | 22 | vars: |
23 | 23 | cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850 |
24 | 24 | cifmw_config_drive_name: test01 |
|
54 | 54 | - 192.168.0.1 |
55 | 55 | ansible.builtin.include_role: |
56 | 56 | name: config_drive |
| 57 | + |
| 58 | + - name: Run config_drive role again without user-data or network-config (soft-clean scenario) |
| 59 | + vars: |
| 60 | + cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850 |
| 61 | + cifmw_config_drive_name: test01 |
| 62 | + cifmw_config_drive_hostname: test01.example.com |
| 63 | + # cifmw_config_drive_userdata is not defined (simulating soft clean) |
| 64 | + # cifmw_config_drive_networkconfig is not defined (simulating soft clean) |
| 65 | + ansible.builtin.include_role: |
| 66 | + name: config_drive |
| 67 | + |
| 68 | + - name: Verify ISO still exists after soft-clean |
| 69 | + ansible.builtin.stat: |
| 70 | + path: "{{ cifmw_config_drive_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts/cifmw_config_drive/de2f369a-1886-4a90-8e50-e419289e6850.iso" |
| 71 | + register: _iso_check |
| 72 | + |
| 73 | + - name: Assert ISO exists |
| 74 | + ansible.builtin.assert: |
| 75 | + that: |
| 76 | + - _iso_check.stat.exists |
| 77 | + fail_msg: "ISO file should exist after soft-clean scenario" |
| 78 | + success_msg: "Soft-clean scenario passed - ISO exists and role didn't fail on skipped tasks" |
| 79 | + |
| 80 | + - name: Run config_drive role again with same configuration (should pass - no changes) |
| 81 | + vars: |
| 82 | + cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850 |
| 83 | + cifmw_config_drive_name: test01 |
| 84 | + cifmw_config_drive_hostname: test01.example.com |
| 85 | + cifmw_config_drive_userdata: |
| 86 | + ssh_authorized_keys: |
| 87 | + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCg1LHRahLiT1NFv4l/XH |
| 88 | + packages: |
| 89 | + - git |
| 90 | + - bind-utils |
| 91 | + write_files: |
| 92 | + - path: /root/test.file |
| 93 | + owner: root:root |
| 94 | + content: |- |
| 95 | + # Test file content |
| 96 | + runcmd: |
| 97 | + - ['sh', '-c', 'echo foo | tee -a /tmp/foo'] |
| 98 | + cifmw_config_drive_networkconfig: |
| 99 | + network: |
| 100 | + version: 2 |
| 101 | + ethernets: |
| 102 | + id0: |
| 103 | + match: |
| 104 | + macaddress: "aa:bb:cc:dd:ee:ff" |
| 105 | + addresses: |
| 106 | + - 192.168.0.101/24 |
| 107 | + routes: |
| 108 | + - to: 0.0.0.0/0 |
| 109 | + via: 192.168.0.1 |
| 110 | + on-link: true |
| 111 | + nameservers: |
| 112 | + addresses: |
| 113 | + - 192.168.0.1 |
| 114 | + ansible.builtin.include_role: |
| 115 | + name: config_drive |
| 116 | + |
| 117 | + - name: Attempt to change user-data on existing ISO (should fail) |
| 118 | + block: |
| 119 | + - name: Include config_drive with modified user-data |
| 120 | + vars: |
| 121 | + cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850 |
| 122 | + cifmw_config_drive_name: test01 |
| 123 | + cifmw_config_drive_hostname: test01.example.com |
| 124 | + cifmw_config_drive_userdata: |
| 125 | + ssh_authorized_keys: |
| 126 | + - ssh-rsa DIFFERENT_KEY_HERE |
| 127 | + packages: |
| 128 | + - vim # Changed from git |
| 129 | + cifmw_config_drive_networkconfig: |
| 130 | + network: |
| 131 | + version: 2 |
| 132 | + ethernets: |
| 133 | + id0: |
| 134 | + match: |
| 135 | + macaddress: "aa:bb:cc:dd:ee:ff" |
| 136 | + addresses: |
| 137 | + - 192.168.0.101/24 |
| 138 | + routes: |
| 139 | + - to: 0.0.0.0/0 |
| 140 | + via: 192.168.0.1 |
| 141 | + on-link: true |
| 142 | + nameservers: |
| 143 | + addresses: |
| 144 | + - 192.168.0.1 |
| 145 | + ansible.builtin.include_role: |
| 146 | + name: config_drive |
| 147 | + |
| 148 | + - name: Fail if role didn't reject the change |
| 149 | + ansible.builtin.fail: |
| 150 | + msg: "Role should have failed when trying to change user-data on existing ISO" |
| 151 | + |
| 152 | + rescue: |
| 153 | + - name: Verify the failure was due to ISO modification attempt |
| 154 | + ansible.builtin.assert: |
| 155 | + that: |
| 156 | + - ansible_failed_result.msg is defined |
| 157 | + - ansible_failed_result.msg is regex('trying to edit an existing ISO', ignorecase=True) |
| 158 | + fail_msg: "Role failed but not with expected error message. Got: {{ ansible_failed_result.msg | default('no message') }}" |
| 159 | + success_msg: "Role correctly rejected attempt to change user-data" |
| 160 | + |
| 161 | + - name: Attempt to change network-config on existing ISO (should fail) |
| 162 | + block: |
| 163 | + - name: Include config_drive with modified network-config |
| 164 | + vars: |
| 165 | + cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850 |
| 166 | + cifmw_config_drive_name: test01 |
| 167 | + cifmw_config_drive_hostname: test01.example.com |
| 168 | + cifmw_config_drive_userdata: |
| 169 | + ssh_authorized_keys: |
| 170 | + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCg1LHRahLiT1NFv4l/XH |
| 171 | + packages: |
| 172 | + - git |
| 173 | + - bind-utils |
| 174 | + write_files: |
| 175 | + - path: /root/test.file |
| 176 | + owner: root:root |
| 177 | + content: |- |
| 178 | + # Test file content |
| 179 | + runcmd: |
| 180 | + - ['sh', '-c', 'echo foo | tee -a /tmp/foo'] |
| 181 | + cifmw_config_drive_networkconfig: |
| 182 | + network: |
| 183 | + version: 2 |
| 184 | + ethernets: |
| 185 | + id0: |
| 186 | + match: |
| 187 | + macaddress: "11:22:33:44:55:66" # Changed MAC address |
| 188 | + addresses: |
| 189 | + - 192.168.0.200/24 # Changed IP |
| 190 | + routes: |
| 191 | + - to: 0.0.0.0/0 |
| 192 | + via: 192.168.0.1 |
| 193 | + on-link: true |
| 194 | + nameservers: |
| 195 | + addresses: |
| 196 | + - 192.168.0.1 |
| 197 | + ansible.builtin.include_role: |
| 198 | + name: config_drive |
| 199 | + |
| 200 | + - name: Fail if role didn't reject the change |
| 201 | + ansible.builtin.fail: |
| 202 | + msg: "Role should have failed when trying to change network-config on existing ISO" |
| 203 | + |
| 204 | + rescue: |
| 205 | + - name: Verify the failure was due to ISO modification attempt |
| 206 | + ansible.builtin.assert: |
| 207 | + that: |
| 208 | + - ansible_failed_result.msg is defined |
| 209 | + - ansible_failed_result.msg is regex('trying to edit an existing ISO', ignorecase=True) |
| 210 | + fail_msg: "Role failed but not with expected error message. Got: {{ ansible_failed_result.msg | default('no message') }}" |
| 211 | + success_msg: "Role correctly rejected attempt to change network-config" |
0 commit comments