diff --git a/changelogs/fragments/9623-pipx-global-latest.yml b/changelogs/fragments/9623-pipx-global-latest.yml new file mode 100644 index 00000000000..c939ea5847f --- /dev/null +++ b/changelogs/fragments/9623-pipx-global-latest.yml @@ -0,0 +1,2 @@ +bugfixes: + - pipx - honor option ``global`` when ``state=latest`` (https://github.com/ansible-collections/community.general/pull/9623). diff --git a/plugins/modules/pipx.py b/plugins/modules/pipx.py index 85c88086a83..e7806d4e75e 100644 --- a/plugins/modules/pipx.py +++ b/plugins/modules/pipx.py @@ -382,12 +382,12 @@ def state_upgrade_shared(self): def state_latest(self): if not self.vars.application or self.vars.force: self.changed = True - args_order = 'state index_url install_deps force python system_site_packages editable pip_args suffix name_source' + args_order = 'state global index_url install_deps force python system_site_packages editable pip_args suffix name_source' with self.runner(args_order, check_mode_skip=True) as ctx: ctx.run(state='install', name_source=[self.vars.name, self.vars.source]) self._capture_results(ctx) - with self.runner('state include_injected index_url force editable pip_args name', check_mode_skip=True) as ctx: + with self.runner('state global include_injected index_url force editable pip_args name', check_mode_skip=True) as ctx: ctx.run(state='upgrade') self._capture_results(ctx) diff --git a/tests/integration/targets/pipx/tasks/main.yml b/tests/integration/targets/pipx/tasks/main.yml index 0e048263711..04086d80cdf 100644 --- a/tests/integration/targets/pipx/tasks/main.yml +++ b/tests/integration/targets/pipx/tasks/main.yml @@ -267,3 +267,6 @@ - name: Include testcase for PR 9103 upgrade --global ansible.builtin.include_tasks: testcase-9103-upgrade-global.yml + + - name: Include testcase for issue 9619 latest --global + ansible.builtin.include_tasks: testcase-9619-latest-global.yml diff --git a/tests/integration/targets/pipx/tasks/testcase-9619-latest-global.yml b/tests/integration/targets/pipx/tasks/testcase-9619-latest-global.yml new file mode 100644 index 00000000000..e06ee438c00 --- /dev/null +++ b/tests/integration/targets/pipx/tasks/testcase-9619-latest-global.yml @@ -0,0 +1,38 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: 9619-Ensure application hello-world is uninstalled + community.general.pipx: + name: hello-world + state: absent + global: true + +- name: 9619-Install application hello-world + community.general.pipx: + name: hello-world + source: hello-world==0.1 + global: true + register: install_hw + +- name: 9619-Upgrade application hello-world + community.general.pipx: + state: latest + name: hello-world + global: true + register: latest_hw + +- name: 9619-Ensure application pylint is uninstalled + community.general.pipx: + name: pylint + state: absent + global: true + +- name: 9619-Assertions + ansible.builtin.assert: + that: + - install_hw is changed + - latest_hw is changed + - latest_hw.cmd[-3] == "upgrade" + - latest_hw.cmd[-2] == "--global"