From 8bfd8bfb09adfae2de94f51ba53306a2d854899f Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 20:59:40 +0100 Subject: [PATCH] [PR #7970/9510988a backport][stable-7] cargo: use the correct path when checking installation status fixing idempotency issue. (#8018) cargo: use the correct path when checking installation status fixing idempotency issue. (#7970) * cargo: use the correct path when checking installation status * Add changelog fragment * Update changelogs/fragments/7970-fix-cargo-path-idempotency.yaml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 9510988abc1a186610fb41797bffdffdb58037aa) Co-authored-by: rbomze <14312790+rbomze@users.noreply.github.com> --- .../fragments/7970-fix-cargo-path-idempotency.yaml | 10 ++++++++++ plugins/modules/cargo.py | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 changelogs/fragments/7970-fix-cargo-path-idempotency.yaml diff --git a/changelogs/fragments/7970-fix-cargo-path-idempotency.yaml b/changelogs/fragments/7970-fix-cargo-path-idempotency.yaml new file mode 100644 index 0000000000..143247bc91 --- /dev/null +++ b/changelogs/fragments/7970-fix-cargo-path-idempotency.yaml @@ -0,0 +1,10 @@ +bugfixes: + - "cargo - fix idempotency issues when using a custom installation path + for packages (using the ``--path`` parameter). + The initial installation runs fine, but subsequent runs use the + ``get_installed()`` function which did not check the given installation + location, before running ``cargo install``. This resulted in a false + ``changed`` state. + Also the removal of packeges using ``state: absent`` failed, as the + installation check did not use the given parameter + (https://github.com/ansible-collections/community.general/pull/7970)." diff --git a/plugins/modules/cargo.py b/plugins/modules/cargo.py index b872361b30..ba9c05ed7b 100644 --- a/plugins/modules/cargo.py +++ b/plugins/modules/cargo.py @@ -137,6 +137,10 @@ class Cargo(object): def get_installed(self): cmd = ["install", "--list"] + if self.path: + cmd.append("--root") + cmd.append(self.path) + data, dummy = self._exec(cmd, True, False, False) package_regex = re.compile(r"^([\w\-]+) v(.+):$")