diff --git a/changelogs/fragments/4330-pacman-packages-update_cache.yml b/changelogs/fragments/4330-pacman-packages-update_cache.yml index cfc0be6f62..595f42c4e3 100644 --- a/changelogs/fragments/4330-pacman-packages-update_cache.yml +++ b/changelogs/fragments/4330-pacman-packages-update_cache.yml @@ -1,6 +1,9 @@ bugfixes: - "pacman - make sure that ``packages`` is always returned when ``name`` or ``upgrade`` is specified, also if nothing is done (https://github.com/ansible-collections/community.general/pull/4329)." +minor_changes: + - "pacman - add ``cache_updated`` return value to when ``update_cache=true`` + (https://github.com/ansible-collections/community.general/pull/4329)." deprecated_features: - "pacman - from community.general 5.0.0 on, the ``changed`` status of ``update_cache`` will no longer be ignored if ``name`` or ``upgrade`` is specified. To keep the old behavior, add something like ``register: result`` and ``changed_when: result.packages | length > 0`` to your task diff --git a/plugins/modules/packaging/os/pacman.py b/plugins/modules/packaging/os/pacman.py index 8d534ed8d6..fa765db142 100644 --- a/plugins/modules/packaging/os/pacman.py +++ b/plugins/modules/packaging/os/pacman.py @@ -125,6 +125,15 @@ packages: elements: str sample: [ package, other-package ] +cache_updated: + description: + - The changed status of C(pacman -Sy). + - Useful when I(name) or I(upgrade=true) are specified next to I(update_cache=true). + returned: success, when I(update_cache=true) + type: bool + sample: false + version_added: 4.6.0 + stdout: description: - Output from pacman. @@ -512,6 +521,7 @@ class Pacman(object): if self.m.check_mode: self.add_exit_infos("Would have updated the package db") self.changed = True + self.exit_params["cache_updated"] = True return cmd = [ @@ -526,7 +536,13 @@ class Pacman(object): rc, stdout, stderr = self.m.run_command(cmd, check_rc=False) + # TODO: check whether the cache was actually updated + # Right now, this only seems to be possible by adding `--debug` and looking + # for `.db: response code` and checking whether the response is 304 (not + # updated) or something else (likely updated) + self.changed = True + self.exit_params["cache_updated"] = True if rc == 0: self.add_exit_infos("Updated package db", stdout=stdout, stderr=stderr)