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