apt - fix module short-circuiting when a package is not installed and only_upgrade is True (#78790)

pull/78794/head
Sloane Hertel 2 years ago committed by GitHub
parent 7683c0ae54
commit f26f3325ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,2 +1,4 @@
bugfixes: bugfixes:
- apt - fix module failure when a package is not installed and only_upgrade=True (https://github.com/ansible/ansible/issues/78762). - >-
apt - Fix module failure when a package is not installed and only_upgrade=True.
Skip that package and check the remaining requested packages for upgrades. (https://github.com/ansible/ansible/issues/78762)

@ -711,8 +711,13 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
package_names.append(name) package_names.append(name)
installed, installed_version, version_installable, has_files = package_status(m, name, version_cmp, version, default_release, cache, state='install') installed, installed_version, version_installable, has_files = package_status(m, name, version_cmp, version, default_release, cache, state='install')
if (not installed_version and not version_installable) or (not installed and only_upgrade): if not installed and only_upgrade:
status = not installed and only_upgrade # only_upgrade upgrades packages that are already installed
# since this package is not installed, skip it
continue
if not installed_version and not version_installable:
status = False
data = dict(msg="no available installation candidate for %s" % package) data = dict(msg="no available installation candidate for %s" % package)
return (status, data) return (status, data)

@ -54,7 +54,7 @@
# https://github.com/ansible/ansible/issues/30638 # https://github.com/ansible/ansible/issues/30638
- block: - block:
- name: Do nothing to install foo=1.0.1 since foo is not installed and only_upgrade is set - name: Don't install foo=1.0.1 since foo is not installed and only_upgrade is set
apt: apt:
name: foo=1.0.1 name: foo=1.0.1
state: present state: present
@ -73,24 +73,30 @@
name: foo=1.0.0 name: foo=1.0.0
allow_unauthenticated: yes allow_unauthenticated: yes
- name: Upgrade foo to 1.0.1 - name: Upgrade foo to 1.0.1 but don't upgrade foobar since it is not installed
apt: apt:
name: foo=1.0.1 name: foobar=1.0.1,foo=1.0.1
state: present state: present
only_upgrade: yes only_upgrade: yes
allow_unauthenticated: yes allow_unauthenticated: yes
register: apt_result register: apt_result
- name: Check install with dpkg - name: Check install with dpkg
shell: dpkg-query -l foo shell: "dpkg-query -l {{ item }}"
register: dpkg_result register: dpkg_result
ignore_errors: yes
loop:
- foobar
- foo
- name: Check if install was successful - name: Check if install was successful
assert: assert:
that: that:
- "apt_result is success" - "apt_result is success"
- "dpkg_result is success" - "dpkg_result.results[0] is failure"
- "'1.0.1' in dpkg_result.stdout" - "'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: always:
- name: Clean up - name: Clean up
apt: apt:

Loading…
Cancel
Save