| 1 |
- name: Test podman_system_connection |
| 2 |
block: |
| 3 |
|
| 4 |
- name: Print podman version |
| 5 |
command: podman version |
| 6 |
|
| 7 |
- name: Generate random values for connection names |
| 8 |
set_fact: |
| 9 |
test_connection_1: "{{ 'ansible-test-conn1-%0x' % ((2**32) | random) }}" |
| 10 |
test_connection_2: "{{ 'ansible-test-conn2-%0x' % ((2**32) | random) }}" |
| 11 |
test_connection_3: "{{ 'ansible-test-conn3-%0x' % ((2**32) | random) }}" |
| 12 |
|
| 13 |
- name: Clean up any existing test connections |
| 14 |
containers.podman.podman_system_connection: |
| 15 |
executable: "{{ test_executable | default('podman') }}" |
| 16 |
name: "{{ item }}" |
| 17 |
state: absent |
| 18 |
ignore_errors: true |
| 19 |
loop: |
| 20 |
- "{{ test_connection_1 }}" |
| 21 |
- "{{ test_connection_2 }}" |
| 22 |
- "{{ test_connection_3 }}" |
| 23 |
|
| 24 |
- name: Test adding a basic unix socket connection |
| 25 |
containers.podman.podman_system_connection: |
| 26 |
executable: "{{ test_executable | default('podman') }}" |
| 27 |
name: "{{ test_connection_1 }}" |
| 28 |
destination: "unix:///tmp/test-socket-{{ test_connection_1 }}.sock" |
| 29 |
state: present |
| 30 |
register: add_result |
| 31 |
|
| 32 |
- name: Check add connection results |
| 33 |
assert: |
| 34 |
that: |
| 35 |
- add_result is changed |
| 36 |
- add_result.connection.Name == test_connection_1 |
| 37 |
- "'unix://' in add_result.connection.URI" |
| 38 |
- add_result.actions | length > 0 |
| 39 |
- "'added' in add_result.actions[0]" |
| 40 |
|
| 41 |
- name: Test idempotency - add same connection again |
| 42 |
containers.podman.podman_system_connection: |
| 43 |
executable: "{{ test_executable | default('podman') }}" |
| 44 |
name: "{{ test_connection_1 }}" |
| 45 |
destination: "unix:///tmp/test-socket-{{ test_connection_1 }}.sock" |
| 46 |
state: present |
| 47 |
register: add_idem_result |
| 48 |
|
| 49 |
- name: Check idempotency |
| 50 |
assert: |
| 51 |
that: |
| 52 |
- add_idem_result is not changed |
| 53 |
- add_idem_result.connection.Name == test_connection_1 |
| 54 |
|
| 55 |
- name: Test adding connection with unix socket |
| 56 |
containers.podman.podman_system_connection: |
| 57 |
executable: "{{ test_executable | default('podman') }}" |
| 58 |
name: "{{ test_connection_2 }}" |
| 59 |
destination: "unix:///tmp/test-socket-{{ test_connection_2 }}.sock" |
| 60 |
state: present |
| 61 |
register: add_custom_result |
| 62 |
|
| 63 |
- name: Check custom connection results |
| 64 |
assert: |
| 65 |
that: |
| 66 |
- add_custom_result is changed |
| 67 |
- add_custom_result.connection.Name == test_connection_2 |
| 68 |
- "'unix://' in add_custom_result.connection.URI" |
| 69 |
- add_custom_result.actions | length > 0 |
| 70 |
|
| 71 |
- name: Test adding connection with default flag |
| 72 |
containers.podman.podman_system_connection: |
| 73 |
executable: "{{ test_executable | default('podman') }}" |
| 74 |
name: "{{ test_connection_3 }}" |
| 75 |
destination: "unix:///tmp/test-socket-{{ test_connection_3 }}.sock" |
| 76 |
default: true |
| 77 |
state: present |
| 78 |
register: add_default_result |
| 79 |
|
| 80 |
- name: Check default connection results |
| 81 |
assert: |
| 82 |
that: |
| 83 |
- add_default_result is changed |
| 84 |
- add_default_result.connection.Name == test_connection_3 |
| 85 |
- add_default_result.connection.Default == true |
| 86 |
|
| 87 |
- name: Test unix socket connection |
| 88 |
containers.podman.podman_system_connection: |
| 89 |
executable: "{{ test_executable | default('podman') }}" |
| 90 |
name: "test-unix" |
| 91 |
destination: "unix:///run/podman/podman.sock" |
| 92 |
state: present |
| 93 |
register: unix_result |
| 94 |
|
| 95 |
- name: Check unix socket connection |
| 96 |
assert: |
| 97 |
that: |
| 98 |
- unix_result is changed |
| 99 |
- unix_result.connection.Name == "test-unix" |
| 100 |
- "'unix://' in unix_result.connection.URI" |
| 101 |
|
| 102 |
- name: Test unix socket connection again for idempotency |
| 103 |
containers.podman.podman_system_connection: |
| 104 |
executable: "{{ test_executable | default('podman') }}" |
| 105 |
name: "test-unix" |
| 106 |
destination: "unix:///run/podman/podman.sock" |
| 107 |
state: present |
| 108 |
register: unix_result2 |
| 109 |
|
| 110 |
- name: Check unix socket connection |
| 111 |
assert: |
| 112 |
that: |
| 113 |
- unix_result2 is not changed |
| 114 |
- unix_result2.connection.Name == "test-unix" |
| 115 |
- "'unix://' in unix_result2.connection.URI" |
| 116 |
|
| 117 |
- name: Test unix socket connection - different |
| 118 |
containers.podman.podman_system_connection: |
| 119 |
executable: "{{ test_executable | default('podman') }}" |
| 120 |
name: "test-unix" |
| 121 |
destination: "unix:///run/podman/podman2.sock" |
| 122 |
state: present |
| 123 |
register: unix_result3 |
| 124 |
|
| 125 |
- name: Check unix socket connection |
| 126 |
assert: |
| 127 |
that: |
| 128 |
- unix_result3 is changed |
| 129 |
- unix_result3.connection.Name == "test-unix" |
| 130 |
- "'unix://' in unix_result3.connection.URI" |
| 131 |
|
| 132 |
- name: Test TCP connection |
| 133 |
containers.podman.podman_system_connection: |
| 134 |
executable: "{{ test_executable | default('podman') }}" |
| 135 |
name: "test-tcp" |
| 136 |
destination: "tcp://localhost:8080" |
| 137 |
state: present |
| 138 |
register: tcp_result |
| 139 |
|
| 140 |
- name: Check TCP connection |
| 141 |
assert: |
| 142 |
that: |
| 143 |
- tcp_result is changed |
| 144 |
- tcp_result.connection.Name == "test-tcp" |
| 145 |
- "'tcp://' in tcp_result.connection.URI" |
| 146 |
|
| 147 |
- name: Test connection rename |
| 148 |
containers.podman.podman_system_connection: |
| 149 |
executable: "{{ test_executable | default('podman') }}" |
| 150 |
name: "{{ test_connection_1 }}" |
| 151 |
new_name: "{{ test_connection_1 }}-renamed" |
| 152 |
state: present |
| 153 |
register: rename_result |
| 154 |
|
| 155 |
- name: Check rename results |
| 156 |
assert: |
| 157 |
that: |
| 158 |
- rename_result is changed |
| 159 |
- rename_result.connection.Name == test_connection_1 + "-renamed" |
| 160 |
|
| 161 |
- name: Test rename non-existent connection (should fail) |
| 162 |
containers.podman.podman_system_connection: |
| 163 |
executable: "{{ test_executable | default('podman') }}" |
| 164 |
name: "non-existent-connection" |
| 165 |
new_name: "new-name" |
| 166 |
state: present |
| 167 |
register: rename_fail_result |
| 168 |
ignore_errors: true |
| 169 |
|
| 170 |
- name: Check rename failure |
| 171 |
assert: |
| 172 |
that: |
| 173 |
- rename_fail_result is failed |
| 174 |
- "'Cannot rename non-existent connection' in rename_fail_result.msg" |
| 175 |
|
| 176 |
- name: Test setting existing connection as default |
| 177 |
containers.podman.podman_system_connection: |
| 178 |
executable: "{{ test_executable | default('podman') }}" |
| 179 |
name: "{{ test_connection_2 }}" |
| 180 |
destination: "unix:///tmp/test-socket-{{ test_connection_2 }}.sock" |
| 181 |
default: true |
| 182 |
state: present |
| 183 |
register: set_default_result |
| 184 |
|
| 185 |
- name: Check set default results |
| 186 |
assert: |
| 187 |
that: |
| 188 |
- set_default_result is changed |
| 189 |
- set_default_result.actions | select('search', 'set as default') | list | length > 0 |
| 190 |
|
| 191 |
- name: Test removing connection |
| 192 |
containers.podman.podman_system_connection: |
| 193 |
executable: "{{ test_executable | default('podman') }}" |
| 194 |
name: "{{ test_connection_2 }}" |
| 195 |
state: absent |
| 196 |
register: remove_result |
| 197 |
|
| 198 |
- name: Check remove results |
| 199 |
assert: |
| 200 |
that: |
| 201 |
- remove_result is changed |
| 202 |
- "'removed' in remove_result.actions[0]" |
| 203 |
|
| 204 |
- name: Test idempotency - remove non-existent connection |
| 205 |
containers.podman.podman_system_connection: |
| 206 |
executable: "{{ test_executable | default('podman') }}" |
| 207 |
name: "{{ test_connection_2 }}" |
| 208 |
state: absent |
| 209 |
register: remove_idem_result |
| 210 |
|
| 211 |
- name: Check remove idempotency |
| 212 |
assert: |
| 213 |
that: |
| 214 |
- remove_idem_result is not changed |
| 215 |
|
| 216 |
- name: Test check mode for adding connection |
| 217 |
containers.podman.podman_system_connection: |
| 218 |
executable: "{{ test_executable | default('podman') }}" |
| 219 |
name: "check-mode-test" |
| 220 |
destination: "unix:///tmp/test-socket-check.sock" |
| 221 |
state: present |
| 222 |
check_mode: true |
| 223 |
register: check_add_result |
| 224 |
|
| 225 |
- name: Verify check mode add |
| 226 |
assert: |
| 227 |
that: |
| 228 |
- check_add_result is changed |
| 229 |
- check_add_result.connection.Name == "check-mode-test" |
| 230 |
|
| 231 |
- name: Verify connection was not actually added in check mode |
| 232 |
containers.podman.podman_system_connection_info: |
| 233 |
executable: "{{ test_executable | default('podman') }}" |
| 234 |
name: "check-mode-test" |
| 235 |
register: check_verify |
| 236 |
|
| 237 |
- name: Check that connection doesn't exist |
| 238 |
assert: |
| 239 |
that: |
| 240 |
- check_verify.connections | length == 0 |
| 241 |
|
| 242 |
- name: Test check mode for removing connection |
| 243 |
containers.podman.podman_system_connection: |
| 244 |
executable: "{{ test_executable | default('podman') }}" |
| 245 |
name: "{{ test_connection_3 }}" |
| 246 |
state: absent |
| 247 |
check_mode: true |
| 248 |
register: check_remove_result |
| 249 |
|
| 250 |
- name: Verify check mode remove |
| 251 |
assert: |
| 252 |
that: |
| 253 |
- check_remove_result is changed |
| 254 |
|
| 255 |
- name: Verify connection still exists after check mode |
| 256 |
containers.podman.podman_system_connection_info: |
| 257 |
executable: "{{ test_executable | default('podman') }}" |
| 258 |
name: "{{ test_connection_3 }}" |
| 259 |
register: check_still_exists |
| 260 |
|
| 261 |
- name: Check that connection still exists |
| 262 |
assert: |
| 263 |
that: |
| 264 |
- check_still_exists.connections | length > 0 |
| 265 |
|
| 266 |
always: |
| 267 |
- name: Clean up test connections |
| 268 |
containers.podman.podman_system_connection: |
| 269 |
executable: "{{ test_executable | default('podman') }}" |
| 270 |
name: "{{ item }}" |
| 271 |
state: absent |
| 272 |
ignore_errors: true |
| 273 |
loop: |
| 274 |
- "{{ test_connection_1 }}" |
| 275 |
- "{{ test_connection_1 }}-renamed" |
| 276 |
- "{{ test_connection_2 }}" |
| 277 |
- "{{ test_connection_3 }}" |
| 278 |
- "test-unix" |
| 279 |
- "test-tcp" |
| 280 |
- "check-mode-test" |