| 1 |
- block: |
| 2 |
- name: Install foo package version 1.0.0 |
| 3 |
apt: |
| 4 |
name: foo=1.0.0 |
| 5 |
allow_unauthenticated: yes |
| 6 |
register: apt_result |
| 7 |
|
| 8 |
- name: Check install with dpkg |
| 9 |
shell: dpkg-query -l foo |
| 10 |
register: dpkg_result |
| 11 |
|
| 12 |
- name: Check if install was successful |
| 13 |
assert: |
| 14 |
that: |
| 15 |
- "apt_result is success" |
| 16 |
- "dpkg_result is success" |
| 17 |
- "'1.0.0' in dpkg_result.stdout" |
| 18 |
|
| 19 |
- name: Update to foo version 1.0.1 |
| 20 |
apt: |
| 21 |
name: foo |
| 22 |
state: latest |
| 23 |
allow_unauthenticated: yes |
| 24 |
register: apt_result |
| 25 |
|
| 26 |
- name: Check install with dpkg |
| 27 |
shell: dpkg-query -l foo |
| 28 |
register: dpkg_result |
| 29 |
|
| 30 |
- name: Check if install was successful |
| 31 |
assert: |
| 32 |
that: |
| 33 |
- "apt_result is success" |
| 34 |
- "dpkg_result is success" |
| 35 |
- "'1.0.1' in dpkg_result.stdout" |
| 36 |
always: |
| 37 |
- name: Clean up |
| 38 |
apt: |
| 39 |
name: foo |
| 40 |
state: absent |
| 41 |
allow_unauthenticated: yes |
| 42 |
|
| 43 |
- name: Try to install non-existent version |
| 44 |
apt: |
| 45 |
name: foo=99 |
| 46 |
state: present |
| 47 |
ignore_errors: true |
| 48 |
register: apt_result |
| 49 |
|
| 50 |
- name: Check if install failed |
| 51 |
assert: |
| 52 |
that: |
| 53 |
- apt_result is failed |
| 54 |
|
| 55 |
# https://github.com/ansible/ansible/issues/30638 |
| 56 |
- block: |
| 57 |
- name: Don't install foo=1.0.1 since foo is not installed and only_upgrade is set |
| 58 |
apt: |
| 59 |
name: foo=1.0.1 |
| 60 |
state: present |
| 61 |
only_upgrade: yes |
| 62 |
allow_unauthenticated: yes |
| 63 |
ignore_errors: yes |
| 64 |
register: apt_result |
| 65 |
|
| 66 |
- name: Check that foo was not upgraded |
| 67 |
assert: |
| 68 |
that: |
| 69 |
- "apt_result is not changed" |
| 70 |
- "apt_result is success" |
| 71 |
|
| 72 |
- apt: |
| 73 |
name: foo=1.0.0 |
| 74 |
allow_unauthenticated: yes |
| 75 |
|
| 76 |
- name: Upgrade foo to 1.0.1 but don't upgrade foobar since it is not installed |
| 77 |
apt: |
| 78 |
name: foobar=1.0.1,foo=1.0.1 |
| 79 |
state: present |
| 80 |
only_upgrade: yes |
| 81 |
allow_unauthenticated: yes |
| 82 |
register: apt_result |
| 83 |
|
| 84 |
- name: Check install with dpkg |
| 85 |
shell: "dpkg-query -l {{ item }}" |
| 86 |
register: dpkg_result |
| 87 |
ignore_errors: yes |
| 88 |
loop: |
| 89 |
- foobar |
| 90 |
- foo |
| 91 |
|
| 92 |
- name: Check if install was successful |
| 93 |
assert: |
| 94 |
that: |
| 95 |
- "apt_result is success" |
| 96 |
- "dpkg_result.results[0] is failure" |
| 97 |
- "'1.0.1' not in dpkg_result.results[0].stdout" |
| 98 |
- "dpkg_result.results[1] is success" |
| 99 |
- "'1.0.1' in dpkg_result.results[1].stdout" |
| 100 |
always: |
| 101 |
- name: Clean up |
| 102 |
apt: |
| 103 |
name: foo |
| 104 |
state: absent |
| 105 |
allow_unauthenticated: yes |
| 106 |
|
| 107 |
- block: |
| 108 |
- name: Install foo=1.0.0 |
| 109 |
apt: |
| 110 |
name: foo=1.0.0 |
| 111 |
|
| 112 |
- name: Run version test matrix |
| 113 |
apt: |
| 114 |
name: foo{{ item.0 }} |
| 115 |
default_release: '{{ item.1 }}' |
| 116 |
state: '{{ item.2 | ternary("latest","present") }}' |
| 117 |
check_mode: true |
| 118 |
register: apt_result |
| 119 |
loop: |
| 120 |
# [filter, release, state_latest, expected] |
| 121 |
- ["", null, false, null] |
| 122 |
- ["", null, true, "1.0.1"] |
| 123 |
- ["=1.0.0", null, false, null] |
| 124 |
- ["=1.0.0", null, true, null] |
| 125 |
- ["=1.0.1", null, false, "1.0.1"] |
| 126 |
#- ["=1.0.*", null, false, null] # legacy behavior. should not upgrade without state=latest |
| 127 |
- ["=1.0.*", null, true, "1.0.1"] |
| 128 |
- [">=1.0.0", null, false, null] |
| 129 |
- [">=1.0.0", null, true, "1.0.1"] |
| 130 |
- [">=1.0.1", null, false, "1.0.1"] |
| 131 |
- ["", "testing", false, null] |
| 132 |
- ["", "testing", true, "2.0.1"] |
| 133 |
- ["=2.0.0", null, false, "2.0.0"] |
| 134 |
- [">=2.0.0", "testing", false, "2.0.1"] |
| 135 |
|
| 136 |
- name: Validate version test matrix |
| 137 |
assert: |
| 138 |
that: |
| 139 |
- (item.item.3 is not none) == (item.stdout is defined) |
| 140 |
- item.item.3 is none or "Inst foo [1.0.0] (" + item.item.3 + " localhost [all])" in item.stdout_lines |
| 141 |
loop: '{{ apt_result.results }}' |
| 142 |
|
| 143 |
- name: Pin foo=1.0.0 |
| 144 |
copy: |
| 145 |
content: |- |
| 146 |
Package: foo |
| 147 |
Pin: version 1.0.0 |
| 148 |
Pin-Priority: 1000 |
| 149 |
dest: /etc/apt/preferences.d/foo |
| 150 |
|
| 151 |
- name: Run pinning version test matrix |
| 152 |
apt: |
| 153 |
name: foo{{ item.0 }} |
| 154 |
default_release: '{{ item.1 }}' |
| 155 |
state: '{{ item.2 | ternary("latest","present") }}' |
| 156 |
check_mode: true |
| 157 |
ignore_errors: true |
| 158 |
register: apt_result |
| 159 |
loop: |
| 160 |
# [filter, release, state_latest, expected] # expected=null for no change. expected=False to assert an error |
| 161 |
- ["", null, false, null] |
| 162 |
- ["", null, true, null] |
| 163 |
- ["=1.0.0", null, false, null] |
| 164 |
- ["=1.0.0", null, true, null] |
| 165 |
- ["=1.0.1", null, false, "1.0.1"] |
| 166 |
#- ["=1.0.*", null, false, null] # legacy behavior. should not upgrade without state=latest |
| 167 |
- ["=1.0.*", null, true, "1.0.1"] |
| 168 |
- [">=1.0.0", null, false, null] |
| 169 |
- [">=1.0.0", null, true, null] |
| 170 |
- [">=1.0.1", null, false, False] |
| 171 |
- ["", "testing", false, null] |
| 172 |
- ["", "testing", true, null] |
| 173 |
- ["=2.0.0", null, false, "2.0.0"] |
| 174 |
- [">=2.0.0", "testing", false, False] |
| 175 |
|
| 176 |
- name: Validate pinning version test matrix |
| 177 |
assert: |
| 178 |
that: |
| 179 |
- (item.item.3 != False) or (item.item.3 == False and item is failed) |
| 180 |
- (item.item.3 is string) == (item.stdout is defined) |
| 181 |
- item.item.3 is not string or "Inst foo [1.0.0] (" + item.item.3 + " localhost [all])" in item.stdout_lines |
| 182 |
loop: '{{ apt_result.results }}' |
| 183 |
|
| 184 |
always: |
| 185 |
- name: Uninstall foo |
| 186 |
apt: |
| 187 |
name: foo |
| 188 |
state: absent |
| 189 |
|
| 190 |
- name: Unpin foo |
| 191 |
file: |
| 192 |
path: /etc/apt/preferences.d/foo |
| 193 |
state: absent |
| 194 |
|
| 195 |
# https://github.com/ansible/ansible/issues/35900 |
| 196 |
- block: |
| 197 |
- name: Disable ubuntu repos so system packages are not upgraded and do not change testing env |
| •198 |
shell: | |
| 199 |
find /etc/apt/sources.list* \ |
| 200 |
\( -name \*.list -or -name \*.sources \) \ |
| 201 |
-and -not -name file_tmp_repo.list \ |
| 202 |
-and -not -name 'local_repo_*.sources' \ |
| 203 |
| xargs -I{} mv {} {}.backup |
| 204 |
|
| 205 |
- name: Install foobar, installs foo as a dependency |
| 206 |
apt: |
| 207 |
name: foobar=1.0.0 |
| 208 |
allow_unauthenticated: yes |
| 209 |
|
| 210 |
- name: mark foobar as auto for next test |
| 211 |
shell: apt-mark auto foobar |
| 212 |
|
| 213 |
- name: Install foobar (marked as manual) (check mode) |
| 214 |
apt: |
| 215 |
name: foobar=1.0.1 |
| 216 |
allow_unauthenticated: yes |
| 217 |
check_mode: yes |
| 218 |
register: manual_foobar_install_check_mode |
| 219 |
|
| 220 |
- name: check foobar was not marked as manually installed by check mode |
| 221 |
shell: apt-mark showmanual | grep foobar |
| 222 |
ignore_errors: yes |
| 223 |
register: showmanual |
| 224 |
|
| 225 |
- assert: |
| 226 |
that: |
| 227 |
- manual_foobar_install_check_mode.changed |
| 228 |
- "'foobar' not in showmanual.stdout" |
| 229 |
|
| 230 |
- name: Install foobar (marked as manual) |
| 231 |
apt: |
| 232 |
name: foobar=1.0.1 |
| 233 |
allow_unauthenticated: yes |
| 234 |
register: manual_foobar_install |
| 235 |
|
| 236 |
- name: check foobar was marked as manually installed |
| 237 |
shell: apt-mark showmanual | grep foobar |
| 238 |
ignore_errors: yes |
| 239 |
register: showmanual |
| 240 |
|
| 241 |
- assert: |
| 242 |
that: |
| 243 |
- manual_foobar_install.changed |
| 244 |
- "'foobar' in showmanual.stdout" |
| 245 |
|
| 246 |
- name: Upgrade foobar to a version which does not depend on foo, autoremove should remove foo |
| 247 |
apt: |
| 248 |
upgrade: dist |
| 249 |
autoremove: yes |
| 250 |
allow_unauthenticated: yes |
| 251 |
|
| 252 |
- name: Check foo with dpkg |
| 253 |
shell: dpkg-query -l foo |
| 254 |
register: dpkg_result |
| 255 |
ignore_errors: yes |
| 256 |
|
| 257 |
- name: Check that foo was removed by autoremove |
| 258 |
assert: |
| 259 |
that: |
| 260 |
- "dpkg_result is failed" |
| 261 |
|
| 262 |
always: |
| 263 |
- name: Clean up |
| 264 |
apt: |
| 265 |
pkg: foo,foobar |
| 266 |
state: absent |
| 267 |
autoclean: yes |
| 268 |
|
| 269 |
- name: Restore ubuntu repos |
| •270 |
shell: | |
| 271 |
find /etc/apt/sources.list* -name \*.backup \ |
| 272 |
| sed 's/\.backup$//' \ |
| 273 |
| xargs -I{} mv {}.backup {} |
| 274 |
|
| 275 |
|
| 276 |
# https://github.com/ansible/ansible/issues/26298 |
| 277 |
- block: |
| 278 |
- name: Disable ubuntu repos so system packages are not upgraded and do not change testing env |
| •279 |
shell: | |
| 280 |
find /etc/apt/sources.list* \ |
| 281 |
\( -name \*.list -or -name \*.sources \) \ |
| 282 |
-and -not -name file_tmp_repo.list \ |
| 283 |
-and -not -name 'local_repo_*.sources' \ |
| 284 |
| xargs -I{} mv {} {}.backup |
| 285 |
|
| 286 |
- name: Install foobar, installs foo as a dependency |
| 287 |
apt: |
| 288 |
name: foobar=1.0.0 |
| 289 |
allow_unauthenticated: yes |
| 290 |
|
| 291 |
- name: Upgrade foobar to a version which does not depend on foo |
| 292 |
apt: |
| 293 |
upgrade: dist |
| 294 |
force: yes # workaround for --allow-unauthenticated used along with upgrade |
| 295 |
|
| 296 |
- name: autoremove should remove foo |
| 297 |
apt: |
| 298 |
autoremove: yes |
| 299 |
register: autoremove_result |
| 300 |
|
| 301 |
- name: Check that autoremove correctly reports changed=True |
| 302 |
assert: |
| 303 |
that: |
| 304 |
- "autoremove_result is changed" |
| 305 |
|
| 306 |
- name: Check foo with dpkg |
| 307 |
shell: dpkg-query -l foo |
| 308 |
register: dpkg_result |
| 309 |
ignore_errors: yes |
| 310 |
|
| 311 |
- name: Check that foo was removed by autoremove |
| 312 |
assert: |
| 313 |
that: |
| 314 |
- "dpkg_result is failed" |
| 315 |
|
| 316 |
- name: Nothing to autoremove |
| 317 |
apt: |
| 318 |
autoremove: yes |
| 319 |
register: autoremove_result |
| 320 |
|
| 321 |
- name: Check that autoremove correctly reports changed=False |
| 322 |
assert: |
| 323 |
that: |
| 324 |
- "autoremove_result is not changed" |
| 325 |
|
| 326 |
- name: Create a fake .deb file for autoclean to remove |
| 327 |
file: |
| 328 |
name: /var/cache/apt/archives/python3-q_2.4-1_all.deb |
| 329 |
state: touch |
| 330 |
|
| 331 |
- name: autoclean fake .deb file |
| 332 |
apt: |
| 333 |
autoclean: yes |
| 334 |
register: autoclean_result |
| 335 |
|
| 336 |
- name: Check if the .deb file exists |
| 337 |
stat: |
| 338 |
path: /var/cache/apt/archives/python3-q_2.4-1_all.deb |
| 339 |
register: stat_result |
| 340 |
|
| 341 |
- name: Check that autoclean correctly reports changed=True and file was removed |
| 342 |
assert: |
| 343 |
that: |
| 344 |
- "autoclean_result is changed" |
| 345 |
- "not stat_result.stat.exists" |
| 346 |
|
| 347 |
- name: Nothing to autoclean |
| 348 |
apt: |
| 349 |
autoclean: yes |
| 350 |
register: autoclean_result |
| 351 |
|
| 352 |
- name: Check that autoclean correctly reports changed=False |
| 353 |
assert: |
| 354 |
that: |
| 355 |
- "autoclean_result is not changed" |
| 356 |
|
| 357 |
always: |
| 358 |
- name: Clean up |
| 359 |
apt: |
| 360 |
pkg: foo,foobar |
| 361 |
state: absent |
| 362 |
autoclean: yes |
| 363 |
|
| 364 |
- name: Restore ubuntu repos |
| •365 |
shell: | |
| 366 |
find /etc/apt/sources.list* -name \*.backup \ |
| 367 |
| sed 's/\.backup$//' \ |
| 368 |
| xargs -I{} mv {}.backup {} |
| 369 |
|
| 370 |
- name: Downgrades |
| 371 |
import_tasks: "downgrade.yml" |
| 372 |
|
| 373 |
- name: Upgrades |
| 374 |
block: |
| 375 |
- import_tasks: "upgrade.yml" |
| 376 |
vars: |
| 377 |
aptitude_present: "{{ True | bool }}" |
| 378 |
upgrade_type: "dist" |
| 379 |
force_apt_get: "{{ False | bool }}" |
| 380 |
|
| 381 |
- name: Check if aptitude is installed |
| 382 |
command: dpkg-query --show --showformat='${db:Status-Abbrev}' aptitude |
| 383 |
register: aptitude_status |
| 384 |
|
| 385 |
- name: Remove aptitude, if installed, to test fall-back to apt-get |
| 386 |
apt: |
| 387 |
pkg: aptitude |
| 388 |
state: absent |
| 389 |
when: |
| 390 |
- aptitude_status.stdout.find('ii') != -1 |
| 391 |
|
| 392 |
- include_tasks: "upgrade.yml" |
| 393 |
vars: |
| 394 |
aptitude_present: "{{ False | bool }}" |
| 395 |
upgrade_type: "{{ item.upgrade_type }}" |
| 396 |
force_apt_get: "{{ item.force_apt_get }}" |
| 397 |
with_items: |
| 398 |
- { upgrade_type: safe, force_apt_get: False } |
| 399 |
- { upgrade_type: full, force_apt_get: False } |
| 400 |
- { upgrade_type: safe, force_apt_get: True } |
| 401 |
- { upgrade_type: full, force_apt_get: True } |
| 402 |
|
| 403 |
- include_tasks: "upgrade_autoremove.yml" |
| 404 |
|
| 405 |
- name: (Re-)Install aptitude, run same tests again |
| 406 |
apt: |
| 407 |
pkg: aptitude |
| 408 |
state: present |
| 409 |
|
| 410 |
- include_tasks: "upgrade.yml" |
| 411 |
vars: |
| 412 |
aptitude_present: "{{ True | bool }}" |
| 413 |
upgrade_type: "{{ item.upgrade_type }}" |
| 414 |
force_apt_get: "{{ item.force_apt_get }}" |
| 415 |
with_items: |
| 416 |
- { upgrade_type: safe, force_apt_get: False } |
| 417 |
- { upgrade_type: full, force_apt_get: False } |
| 418 |
- { upgrade_type: safe, force_apt_get: True } |
| 419 |
- { upgrade_type: full, force_apt_get: True } |
| 420 |
|
| 421 |
- include_tasks: "upgrade_scenarios.yml" |
| 422 |
- include_tasks: "upgrade_autoremove.yml" |
| 423 |
|
| 424 |
- name: Remove aptitude if not originally present |
| 425 |
apt: |
| 426 |
pkg: aptitude |
| 427 |
state: absent |
| 428 |
when: |
| 429 |
- aptitude_status.stdout.find('ii') == -1 |
| 430 |
|
| 431 |
- block: |
| 432 |
- name: Install the foo package with diff=yes |
| 433 |
apt: |
| 434 |
name: foo |
| 435 |
allow_unauthenticated: yes |
| 436 |
diff: yes |
| 437 |
register: apt_result |
| 438 |
|
| 439 |
- name: Check the content of diff.prepared |
| 440 |
assert: |
| 441 |
that: |
| 442 |
- apt_result is success |
| 443 |
- "'The following NEW packages will be installed:\n foo' in apt_result.diff.prepared" |
| 444 |
always: |
| 445 |
- name: Clean up |
| 446 |
apt: |
| 447 |
name: foo |
| 448 |
state: absent |
| 449 |
allow_unauthenticated: yes |
| 450 |
|
| 451 |
- block: |
| 452 |
- name: Install foo package version 1.0.0 with force=yes, implies allow_unauthenticated=yes |
| 453 |
apt: |
| 454 |
name: foo=1.0.0 |
| 455 |
force: yes |
| 456 |
register: apt_result |
| 457 |
|
| 458 |
- name: Check install with dpkg |
| 459 |
shell: dpkg-query -l foo |
| 460 |
register: dpkg_result |
| 461 |
|
| 462 |
- name: Check if install was successful |
| 463 |
assert: |
| 464 |
that: |
| 465 |
- "apt_result is success" |
| 466 |
- "dpkg_result is success" |
| 467 |
- "'1.0.0' in dpkg_result.stdout" |
| 468 |
always: |
| 469 |
- name: Clean up |
| 470 |
apt: |
| 471 |
name: foo |
| 472 |
state: absent |
| 473 |
allow_unauthenticated: yes |