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(.+):$")