Repository: ansible-collections/community.general

Issue:
pipx module: --pip-args: expected one argument
### Summary

When specifying `pip_args` for the `pipx` module, e.g. `pip_args: --no-cache-dir`, they are passed as two arguments to `pipx` while execution:

```
fatal: [mmx-sync.mmx.musc.intra]: FAILED! => changed=false 
  cmd: |-
    /usr/bin/python3 -m pipx install --pip-args --no-cache-dir my_pkg
...
```

However, they must be passed as one argument. The cmd should look like this:

```
/usr/bin/python3 -m pipx install --pip-args="--no-cache-dir" my_pkg
```

### Issue Type

Bug Report

### Component Name

pipx

### Ansible Version

```console
$ ansible --version
ansible [core 2.12.10]
  config file = /home/endr_se/Documents/mmx/ansible/ansible.cfg
  configured module search path = ['/home/endr_se/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/endr_se/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True
```


### Community.general Version

```console
$ ansible-galaxy collection list community.general
# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.8.3  

# /home/user/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.0.1
```


### Configuration

```console
$ ansible-config dump --only-changed
ANSIBLE_NOCOWS(/home/user/Documents/ansible/ansible.cfg) = True
ANSIBLE_PIPELINING(/home/user/Documents/mmx/ansible/ansible.cfg) = True
DEFAULT_HOST_LIST(/home/user/Documents/mmx/ansible/ansible.cfg) = ['/home/user/Documents/ansible/inventory.yml']
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/user/Documents/ansible/ansible.cfg) = True
DEFAULT_ROLES_PATH(/home/user/Documents/ansible/ansible.cfg) = ['/home/user/Documents/ansible/roles', '/home/user/Documents/ansible/roles-common']
DEFAULT_STDOUT_CALLBACK(/home/user/Documents/ansible/ansible.cfg) = community.general.yaml
DIFF_ALWAYS(/home/user/Documents/ansible/ansible.cfg) = True
```


### OS / Environment

Ubuntu 20.04 LTS

### Steps to Reproduce

```yaml
---
- hosts: localhost
  gather_facts: false
  become: false
  tasks:
    - name: Install Python Package pyinstaller
      community.general.pipx:
        name: pyinstaller
        state: present
        system_site_packages: true
        pip_args: "--no-cache-dir"
```


### Expected Results

`--no-cache-dir` should be passed to pip.

### Actual Results

```console
ansible-playbook test-pb.yml
[WARNING]: Collection community.general does not support Ansible version 2.12.10

PLAY [localhost] ********************************************************************************************************************

TASK [Install Python Package pyinstaller] *******************************************************************************************
fatal: [localhost]: FAILED! => changed=false 
  cmd: /usr/bin/python3 -m pipx install --system-site-packages --pip-args --no-cache-dir pyinstaller
  msg: |-
    usage: /usr/bin/python3 -m pipx install [-h] [--include-deps] [--verbose]
                                            [--force] [--suffix SUFFIX]
                                            [--python PYTHON]
                                            [--system-site-packages]
                                            [--index-url INDEX_URL] [--editable]
                                            [--pip-args PIP_ARGS]
                                            package_spec
    /usr/bin/python3 -m pipx install: error: argument --pip-args: expected one argument
  rc: 2
  stderr: |-
    usage: /usr/bin/python3 -m pipx install [-h] [--include-deps] [--verbose]
                                            [--force] [--suffix SUFFIX]
                                            [--python PYTHON]
                                            [--system-site-packages]
                                            [--index-url INDEX_URL] [--editable]
                                            [--pip-args PIP_ARGS]
                                            package_spec
    /usr/bin/python3 -m pipx install: error: argument --pip-args: expected one argument
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>

PLAY RECAP **************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
```

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/pipx.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/pipx.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @russoz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hi @sedrubal thanks for reporting it. I believe I know how to fix it but I am having some very busy days, it's gonna take a couple of days to go through it.

Or much less than that ;-)

Resolving patch:
diff --git a/plugins/module_utils/pipx.py b/plugins/module_utils/pipx.py
--- a/plugins/module_utils/pipx.py
+++ b/plugins/module_utils/pipx.py
@@ -42,7 +42,7 @@ def pipx_runner(module, command, **kwargs):
             system_site_packages=fmt.as_bool("--system-site-packages"),
             _list=fmt.as_fixed(['list', '--include-injected', '--json']),
             editable=fmt.as_bool("--editable"),
-            pip_args=fmt.as_opt_val('--pip-args'),
+            pip_args=fmt.as_opt_eq_val('--pip-args'),
         ),
         environ_update={'USE_EMOJI': '0'},
         check_rc=True,


Test patch:
diff --git a/tests/integration/targets/pipx/tasks/main.yml b/tests/integration/targets/pipx/tasks/main.yml
--- a/tests/integration/targets/pipx/tasks/main.yml
+++ b/tests/integration/targets/pipx/tasks/main.yml
@@ -314,3 +314,28 @@
     that:
       - install_tox_sitewide is changed
       - usrlocaltox.stat.exists
+
+##############################################################################
+# Test for issue 7497
+- name: ensure application pyinstaller is uninstalled
+  community.general.pipx:
+    name: pyinstaller
+    state: absent
+
+- name: Install Python Package pyinstaller
+  community.general.pipx:
+    name: pyinstaller
+    state: present
+    system_site_packages: true
+    pip_args: "--no-cache-dir"
+  register: install_pyinstaller
+
+- name: cleanup pyinstaller
+  community.general.pipx:
+    name: pyinstaller
+    state: absent
+
+- name: check assertions
+  assert:
+    that:
+      - install_pyinstaller is changed