Skip to content

pipx : Support package with version constraint in parameter name #7815

Closed
@ldrouard

Description

@ldrouard

Summary

Using pipx module to install a python package with constraint version in name is not idempotent.

UPDATE: This issue is now meant to request that the module accepts version specifiers in the parameter name. See comments below for rationale on how we got to this.

Issue Type

Feature Request

Component Name

pipx

Ansible Version

$ ansible --version

ansible [core 2.16.2]
  config file = /home/xxx/dev/ansible/ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/xxx/.local/pipx/venvs/molecule-plugins/lib/python3.10/site-packages/ansible
  ansible collection location = /home/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/xxx/.local/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/home/xxx/.local/pipx/venvs/molecule-plugins/bin/python)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /home/xxx/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.2.0

Configuration

$ ansible-config dump --only-changed

CONFIG_FILE() = /home/xxx/dev/ansible/ansible.cfg
DEFAULT_FORKS(/home/xxx/dev/ansible/ansible.cfg) = 10
DEFAULT_HOST_LIST(/home/xxx/dev/ansible/ansible.cfg) = ['/home/xxx/dev/ansible/inventories']
DEFAULT_LOCAL_TMP(/home/xxx/dev/ansible/ansible.cfg) = /home/xxx/dev/ansible/tmp/ansible-local-100223qzoog_xv
DEFAULT_LOG_PATH(/home/xxx/dev/ansible/ansible.cfg) = /home/xxx/dev/ansible/log/ansible.log
DEFAULT_ROLES_PATH(/home/xxx/dev/ansible/ansible.cfg) = ['/home/xxx/dev/ansible/roles']
DEFAULT_TIMEOUT(/home/xxx/dev/ansible/ansible.cfg) = 7
HOST_KEY_CHECKING(/home/xxx/dev/ansible/ansible.cfg) = False
INVENTORY_IGNORE_EXTS(/home/xxx/dev/ansible/ansible.cfg) = ['~', '.orig', '.bak', '.ini', '.cfg', '.retry', '.pyc', '.pyo']
RETRY_FILES_SAVE_PATH(/home/xxx/dev/ansible/ansible.cfg) = /home/xxx/dev/ansible/tmp/retry

OS / Environment

Ubuntu 22.04

Steps to Reproduce

Run this minimal playbook

$ ansible-playbook -i inventories/personal --vault-password-file ~/.vault_pass playbook/pipx_debug.yml -vv
---
- name: "Test"
  # Stop execution on first error
  any_errors_fatal: true

  # Hosts selection to run playbook
  hosts:
    localhost
  gather_facts: false

  tasks:
    - name: Step 1 - Install or remove pip packages
      community.general.pipx:
        name: test-pip-install==0.0.3
        state: present

    - name: Step 2 - Install or remove pip packages
      community.general.pipx:
        name: test-pip-install==0.0.3
        state: present

Expected Results

With this playbook, the first step install a pip package with a version constraint (test-pip-install==0.0.3). => State = changed

The second step (same as step 1) should be a "No Change" (Ok)... but it isn't.

The same test without version constraint work well, Eg.

---
...
  tasks:
    - name: Step 1 - Install or remove pip packages
      community.general.pipx:
        name: test-pip-install
        state: present

    - name: Step 2 - Install or remove pip packages
      community.general.pipx:
        name: test-pip-install
        state: present

Actual Results

$ ansible-playbook -i inventories/personal --vault-password-file ~/.vault_pass playbook/pipx_debug.yml -vv

ansible-playbook [core 2.16.2]
  config file = /home/xxx/dev/ansible/ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/xxx/.local/pipx/venvs/molecule-plugins/lib/python3.10/site-packages/ansible
  ansible collection location = /home/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/xxx/.local/bin/ansible-playbook
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/home/xxx/.local/pipx/venvs/molecule-plugins/bin/python)
  jinja version = 3.1.2
  libyaml = True
Using /home/xxx/dev/ansible/ansible.cfg as config file
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: pipx_debug.yml ***************************************************************************************************************************************************************
1 plays in playbook/pipx_debug.yml

PLAY [Test] ****************************************************************************************************************************************************************************

TASK [Step 1 - Install or remove pip packages] *****************************************************************************************************************************************
task path: /home/xxx/dev/ansible/playbook/pipx_debug.yml:12
changed: [localhost] => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "application": {}, "changed": true, "cmd": ["/usr/bin/python3", "-m", "pipx", "install", "test-pip-install==0.0.3"], "force": false, "index_url": null, "name": "test-pip-install==0.0.3", "source": null, "stderr": "creating virtual environment...\ninstalling test-pip-install from spec 'test-pip-install==0.0.3'...\ndone! \n", "stderr_lines": ["creating virtual environment...", "installing test-pip-install from spec 'test-pip-install==0.0.3'...", "done! "], "stdout": "  installed package test-pip-install 0.0.3, installed using Python 3.10.12\n  These apps are now globally available\n    - test-pip-install\n", "stdout_lines": ["  installed package test-pip-install 0.0.3, installed using Python 3.10.12", "  These apps are now globally available", "    - test-pip-install"]}

TASK [Step 2 - Install or remove pip packages] *****************************************************************************************************************************************
task path: /home/xxx/dev/ansible/playbook/pipx_debug.yml:17
changed: [localhost] => {"application": {}, "changed": true, "cmd": ["/usr/bin/python3", "-m", "pipx", "install", "test-pip-install==0.0.3"], "force": false, "index_url": null, "name": "test-pip-install==0.0.3", "source": null, "stderr": "", "stderr_lines": [], "stdout": "'test-pip-install' already seems to be installed. Not modifying existing\ninstallation in '/home/xxx/.local/pipx/venvs/test-pip-install'. Pass\n'--force' to force installation.\n", "stdout_lines": ["'test-pip-install' already seems to be installed. Not modifying existing", "installation in '/home/xxx/.local/pipx/venvs/test-pip-install'. Pass", "'--force' to force installation."]}

PLAY RECAP *****************************************************************************************************************************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureThis issue/PR relates to a feature requesthas_prmodulemodulepluginsplugin (any type)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions