Repository: ansible-collections/community.general

Issue:
cargo shows changed status for some of the packages that are already installed
### Summary

`community.general.cargo` doesn't always return "ok" status for packages that are already installed.

From my testing, I get "ok" for these:
- bat
- exa
- ripgrep
- sheldon
- tealdeer

And "changed" for these:
- cargo-update
- git-interactive-rebase-tool
- git-delta
- python-launcher

All of these are installed through Ansible on a fresh system.

### Issue Type

Bug Report

### Component Name

cargo

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.12.1]
  config file = None
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/ans/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ubuntu/ans/bin/ansible
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
  jinja version = 3.0.3
  libyaml = True
```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general

# /home/ubuntu/ans/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.3.0
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
[Command did not return anything.]
```


### OS / Environment

Tested on:
- Linux Mint 20.2
- Ubuntu 20.04 LTS (this one was in WSL)

### Steps to Reproduce

1. Create a file (`example_playbook.yaml`):
```yaml (paste below)
- hosts: localhost
  connection: local
  tasks:
    - community.general.cargo:
        name: git-interactive-rebase-tool
        state: present
    - community.general.cargo:
        name: exa
        state: present
```
2. Run `ansible-playbook example_playbook.yaml`.
3. Run `ansible-playbook example_playbook.yaml` again.
4. See that `git-interactive-rebase-tool` is shown as changed and `exa` isn't while in reality, both were not changed.

### Expected Results

I expected the status for both tasks to be "ok".

### Actual Results

```console (paste below)
$ ansible-playbook example_playbook.yaml
ansible-playbook [core 2.12.1]
  config file = None
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/ans/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ubuntu/ans/bin/ansible-playbook
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
  jinja version = 3.0.3
  libyaml = True
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
Loading collection community.general from /home/ubuntu/ans/lib/python3.8/site-packages/ansible_collections/community/general
Loading callback plugin default of type stdout, v2.0 from /home/ubuntu/ans/lib/python3.8/site-packages/ansible/plugins/callback/default.py
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: example_playbook.yaml ************************************************
Positional arguments: example_playbook.yaml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in example_playbook.yaml

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
task path: /home/ubuntu/example_playbook.yaml:1
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
<127.0.0.1> EXEC /bin/sh -c 'echo ~ubuntu && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ubuntu/.ansible/tmp `"&& mkdir "` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349738.3392313-3598-151431594473181 `" && echo ansible-tmp-1642349738.3392313-3598-151431594473181="` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349738.3392313-3598-151431594473181 `" ) && sleep 0'
Using module file /home/ubuntu/ans/lib/python3.8/site-packages/ansible/modules/setup.py
<127.0.0.1> PUT /home/ubuntu/.ansible/tmp/ansible-local-3592b2n6djsn/tmpyjllykdz TO /home/ubuntu/.ansible/tmp/ansible-tmp-1642349738.3392313-3598-151431594473181/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1642349738.3392313-3598-151431594473181/ /home/ubuntu/.ansible/tmp/ansible-tmp-1642349738.3392313-3598-151431594473181/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/ubuntu/ans/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1642349738.3392313-3598-151431594473181/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ubuntu/.ansible/tmp/ansible-tmp-1642349738.3392313-3598-151431594473181/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [community.general.cargo] *************************************************
task path: /home/ubuntu/example_playbook.yaml:4
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
<127.0.0.1> EXEC /bin/sh -c 'echo ~ubuntu && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ubuntu/.ansible/tmp `"&& mkdir "` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349740.2057781-3716-40839843245069 `" && echo ansible-tmp-1642349740.2057781-3716-40839843245069="` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349740.2057781-3716-40839843245069 `" ) && sleep 0'
Using module file /home/ubuntu/ans/lib/python3.8/site-packages/ansible_collections/community/general/plugins/modules/cargo.py
<127.0.0.1> PUT /home/ubuntu/.ansible/tmp/ansible-local-3592b2n6djsn/tmpaplgpavm TO /home/ubuntu/.ansible/tmp/ansible-tmp-1642349740.2057781-3716-40839843245069/AnsiballZ_cargo.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1642349740.2057781-3716-40839843245069/ /home/ubuntu/.ansible/tmp/ansible-tmp-1642349740.2057781-3716-40839843245069/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/ubuntu/ans/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1642349740.2057781-3716-40839843245069/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ubuntu/.ansible/tmp/ansible-tmp-1642349740.2057781-3716-40839843245069/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "name": [
                "git-interactive-rebase-tool"
            ],
            "path": null,
            "state": "present",
            "version": null
        }
    },
    "stderr": "    Updating crates.io index\n  Installing git-interactive-rebase-tool v2.1.0\n   Compiling libc v0.2.112\n   Compiling cfg-if v1.0.0\n   Compiling pkg-config v0.3.24\n   Compiling autocfg v1.0.1\n   Compiling log v0.4.14\n   Compiling tinyvec_macros v0.1.0\n   Compiling parking_lot_core v0.8.5\n   Compiling matches v0.1.9\n   Compiling bitflags v1.3.2\n   Compiling arrayvec v0.4.12\n   Compiling percent-encoding v2.1.0\n   Compiling unicode-bidi v0.3.7\n   Compiling scopeguard v1.1.0\n   Compiling smallvec v1.8.0\n   Compiling anyhow v1.0.52\n   Compiling unicode-width v0.1.9\n   Compiling nodrop v0.1.14\n   Compiling itoa v0.4.8\n   Compiling lazy_static v1.4.0\n   Compiling vec_map v0.8.2\n   Compiling strsim v0.8.0\n   Compiling ansi_term v0.12.1\n   Compiling unicode-segmentation v1.8.0\n   Compiling xi-unicode v0.3.0\n   Compiling instant v0.1.12\n   Compiling tinyvec v1.5.1\n   Compiling num-traits v0.2.14\n   Compiling num-integer v0.1.44\n   Compiling form_urlencoded v1.0.1\n   Compiling lock_api v0.4.5\n   Compiling textwrap v0.11.0\n   Compiling unicode-normalization v0.1.19\n   Compiling jobserver v0.1.24\n   Compiling signal-hook-registry v1.4.0\n   Compiling mio v0.7.14\n   Compiling atty v0.2.14\n   Compiling time v0.1.44\n   Compiling num-format v0.4.0\n   Compiling cc v1.0.72\n   Compiling idna v0.2.3\n   Compiling signal-hook v0.1.17\n   Compiling parking_lot v0.11.2\n   Compiling clap v2.34.0\n   Compiling url v2.2.2\n   Compiling chrono v0.4.19\n   Compiling crossterm v0.19.0\n   Compiling libz-sys v1.1.3\n   Compiling libgit2-sys v0.12.26+1.3.0\n   Compiling git2 v0.13.25\n   Compiling git-interactive-rebase-tool v2.1.0\n    Finished release [optimized] target(s) in 1m 35s\n  Installing /home/ubuntu/.cargo/bin/interactive-rebase-tool\n   Installed package `git-interactive-rebase-tool v2.1.0` (executable `interactive-rebase-tool`)\n",
    "stderr_lines": [
        "    Updating crates.io index",
        "  Installing git-interactive-rebase-tool v2.1.0",
        "   Compiling libc v0.2.112",
        "   Compiling cfg-if v1.0.0",
        "   Compiling pkg-config v0.3.24",
        "   Compiling autocfg v1.0.1",
        "   Compiling log v0.4.14",
        "   Compiling tinyvec_macros v0.1.0",
        "   Compiling parking_lot_core v0.8.5",
        "   Compiling matches v0.1.9",
        "   Compiling bitflags v1.3.2",
        "   Compiling arrayvec v0.4.12",
        "   Compiling percent-encoding v2.1.0",
        "   Compiling unicode-bidi v0.3.7",
        "   Compiling scopeguard v1.1.0",
        "   Compiling smallvec v1.8.0",
        "   Compiling anyhow v1.0.52",
        "   Compiling unicode-width v0.1.9",
        "   Compiling nodrop v0.1.14",
        "   Compiling itoa v0.4.8",
        "   Compiling lazy_static v1.4.0",
        "   Compiling vec_map v0.8.2",
        "   Compiling strsim v0.8.0",
        "   Compiling ansi_term v0.12.1",
        "   Compiling unicode-segmentation v1.8.0",
        "   Compiling xi-unicode v0.3.0",
        "   Compiling instant v0.1.12",
        "   Compiling tinyvec v1.5.1",
        "   Compiling num-traits v0.2.14",
        "   Compiling num-integer v0.1.44",
        "   Compiling form_urlencoded v1.0.1",
        "   Compiling lock_api v0.4.5",
        "   Compiling textwrap v0.11.0",
        "   Compiling unicode-normalization v0.1.19",
        "   Compiling jobserver v0.1.24",
        "   Compiling signal-hook-registry v1.4.0",
        "   Compiling mio v0.7.14",
        "   Compiling atty v0.2.14",
        "   Compiling time v0.1.44",
        "   Compiling num-format v0.4.0",
        "   Compiling cc v1.0.72",
        "   Compiling idna v0.2.3",
        "   Compiling signal-hook v0.1.17",
        "   Compiling parking_lot v0.11.2",
        "   Compiling clap v2.34.0",
        "   Compiling url v2.2.2",
        "   Compiling chrono v0.4.19",
        "   Compiling crossterm v0.19.0",
        "   Compiling libz-sys v1.1.3",
        "   Compiling libgit2-sys v0.12.26+1.3.0",
        "   Compiling git2 v0.13.25",
        "   Compiling git-interactive-rebase-tool v2.1.0",
        "    Finished release [optimized] target(s) in 1m 35s",
        "  Installing /home/ubuntu/.cargo/bin/interactive-rebase-tool",
        "   Installed package `git-interactive-rebase-tool v2.1.0` (executable `interactive-rebase-tool`)"
    ],
    "stdout": "",
    "stdout_lines": []
}

TASK [community.general.cargo] *************************************************
task path: /home/ubuntu/example_playbook.yaml:7
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
<127.0.0.1> EXEC /bin/sh -c 'echo ~ubuntu && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ubuntu/.ansible/tmp `"&& mkdir "` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349835.6476634-6344-126932322812930 `" && echo ansible-tmp-1642349835.6476634-6344-126932322812930="` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349835.6476634-6344-126932322812930 `" ) && sleep 0'
Using module file /home/ubuntu/ans/lib/python3.8/site-packages/ansible_collections/community/general/plugins/modules/cargo.py
<127.0.0.1> PUT /home/ubuntu/.ansible/tmp/ansible-local-3592b2n6djsn/tmp3sxtnw15 TO /home/ubuntu/.ansible/tmp/ansible-tmp-1642349835.6476634-6344-126932322812930/AnsiballZ_cargo.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1642349835.6476634-6344-126932322812930/ /home/ubuntu/.ansible/tmp/ansible-tmp-1642349835.6476634-6344-126932322812930/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/ubuntu/ans/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1642349835.6476634-6344-126932322812930/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ubuntu/.ansible/tmp/ansible-tmp-1642349835.6476634-6344-126932322812930/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "name": [
                "exa"
            ],
            "path": null,
            "state": "present",
            "version": null
        }
    },
    "stderr": "    Updating crates.io index\n  Installing exa v0.10.1\n Downloading crates ...\n  Downloaded num_cpus v1.13.1\n   Compiling libc v0.2.112\n   Compiling pkg-config v0.3.24\n   Compiling unicode-width v0.1.9\n   Compiling tinyvec_macros v0.1.0\n   Compiling matches v0.1.9\n   Compiling log v0.4.14\n   Compiling percent-encoding v2.1.0\n   Compiling unicode-bidi v0.3.7\n   Compiling cfg-if v1.0.0\n   Compiling bitflags v1.3.2\n   Compiling byteorder v1.4.3\n   Compiling natord v1.0.9\n   Compiling lazy_static v1.4.0\n   Compiling ansi_term v0.12.1\n   Compiling scoped_threadpool v0.1.9\n   Compiling glob v0.3.0\n   Compiling number_prefix v0.4.0\n   Compiling tinyvec v1.5.1\n   Compiling pad v0.1.6\n   Compiling term_grid v0.1.7\n   Compiling form_urlencoded v1.0.1\n   Compiling unicode-normalization v0.1.19\n   Compiling jobserver v0.1.24\n   Compiling locale v0.2.2\n   Compiling users v0.11.0\n   Compiling term_size v0.3.2\n   Compiling num_cpus v1.13.1\n   Compiling cc v1.0.72\n   Compiling idna v0.2.3\n   Compiling datetime v0.5.2\n   Compiling url v2.2.2\n   Compiling zoneinfo_compiled v0.5.1\n   Compiling exa v0.10.1\n   Compiling libz-sys v1.1.3\n   Compiling libgit2-sys v0.12.26+1.3.0\n   Compiling git2 v0.13.25\n    Finished release [optimized] target(s) in 1m 18s\n  Installing /home/ubuntu/.cargo/bin/exa\n   Installed package `exa v0.10.1` (executable `exa`)\n",
    "stderr_lines": [
        "    Updating crates.io index",
        "  Installing exa v0.10.1",
        " Downloading crates ...",
        "  Downloaded num_cpus v1.13.1",
        "   Compiling libc v0.2.112",
        "   Compiling pkg-config v0.3.24",
        "   Compiling unicode-width v0.1.9",
        "   Compiling tinyvec_macros v0.1.0",
        "   Compiling matches v0.1.9",
        "   Compiling log v0.4.14",
        "   Compiling percent-encoding v2.1.0",
        "   Compiling unicode-bidi v0.3.7",
        "   Compiling cfg-if v1.0.0",
        "   Compiling bitflags v1.3.2",
        "   Compiling byteorder v1.4.3",
        "   Compiling natord v1.0.9",
        "   Compiling lazy_static v1.4.0",
        "   Compiling ansi_term v0.12.1",
        "   Compiling scoped_threadpool v0.1.9",
        "   Compiling glob v0.3.0",
        "   Compiling number_prefix v0.4.0",
        "   Compiling tinyvec v1.5.1",
        "   Compiling pad v0.1.6",
        "   Compiling term_grid v0.1.7",
        "   Compiling form_urlencoded v1.0.1",
        "   Compiling unicode-normalization v0.1.19",
        "   Compiling jobserver v0.1.24",
        "   Compiling locale v0.2.2",
        "   Compiling users v0.11.0",
        "   Compiling term_size v0.3.2",
        "   Compiling num_cpus v1.13.1",
        "   Compiling cc v1.0.72",
        "   Compiling idna v0.2.3",
        "   Compiling datetime v0.5.2",
        "   Compiling url v2.2.2",
        "   Compiling zoneinfo_compiled v0.5.1",
        "   Compiling exa v0.10.1",
        "   Compiling libz-sys v1.1.3",
        "   Compiling libgit2-sys v0.12.26+1.3.0",
        "   Compiling git2 v0.13.25",
        "    Finished release [optimized] target(s) in 1m 18s",
        "  Installing /home/ubuntu/.cargo/bin/exa",
        "   Installed package `exa v0.10.1` (executable `exa`)"
    ],
    "stdout": "",
    "stdout_lines": []
}
META: ran handlers
META: ran handlers

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   



$ ansible-playbook example_playbook.yaml
ansible-playbook [core 2.12.1]
  config file = None
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/ans/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ubuntu/ans/bin/ansible-playbook
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
  jinja version = 3.0.3
  libyaml = True
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
Loading collection community.general from /home/ubuntu/ans/lib/python3.8/site-packages/ansible_collections/community/general
Loading callback plugin default of type stdout, v2.0 from /home/ubuntu/ans/lib/python3.8/site-packages/ansible/plugins/callback/default.py
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: example_playbook.yaml ************************************************
Positional arguments: example_playbook.yaml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in example_playbook.yaml

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
task path: /home/ubuntu/example_playbook.yaml:1
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
<127.0.0.1> EXEC /bin/sh -c 'echo ~ubuntu && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ubuntu/.ansible/tmp `"&& mkdir "` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349990.5748734-8270-91340278123238 `" && echo ansible-tmp-1642349990.5748734-8270-91340278123238="` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349990.5748734-8270-91340278123238 `" ) && sleep 0'
Using module file /home/ubuntu/ans/lib/python3.8/site-packages/ansible/modules/setup.py
<127.0.0.1> PUT /home/ubuntu/.ansible/tmp/ansible-local-82645tywg09a/tmp4uf2kenm TO /home/ubuntu/.ansible/tmp/ansible-tmp-1642349990.5748734-8270-91340278123238/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1642349990.5748734-8270-91340278123238/ /home/ubuntu/.ansible/tmp/ansible-tmp-1642349990.5748734-8270-91340278123238/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/ubuntu/ans/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1642349990.5748734-8270-91340278123238/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ubuntu/.ansible/tmp/ansible-tmp-1642349990.5748734-8270-91340278123238/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [community.general.cargo] *************************************************
task path: /home/ubuntu/example_playbook.yaml:4
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
<127.0.0.1> EXEC /bin/sh -c 'echo ~ubuntu && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ubuntu/.ansible/tmp `"&& mkdir "` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349992.213021-8388-178428474268699 `" && echo ansible-tmp-1642349992.213021-8388-178428474268699="` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349992.213021-8388-178428474268699 `" ) && sleep 0'
Using module file /home/ubuntu/ans/lib/python3.8/site-packages/ansible_collections/community/general/plugins/modules/cargo.py
<127.0.0.1> PUT /home/ubuntu/.ansible/tmp/ansible-local-82645tywg09a/tmpbyb9okuf TO /home/ubuntu/.ansible/tmp/ansible-tmp-1642349992.213021-8388-178428474268699/AnsiballZ_cargo.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1642349992.213021-8388-178428474268699/ /home/ubuntu/.ansible/tmp/ansible-tmp-1642349992.213021-8388-178428474268699/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/ubuntu/ans/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1642349992.213021-8388-178428474268699/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ubuntu/.ansible/tmp/ansible-tmp-1642349992.213021-8388-178428474268699/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "name": [
                "git-interactive-rebase-tool"
            ],
            "path": null,
            "state": "present",
            "version": null
        }
    },
    "stderr": "    Updating crates.io index\n     Ignored package `git-interactive-rebase-tool v2.1.0` is already installed, use --force to override\n",
    "stderr_lines": [
        "    Updating crates.io index",
        "     Ignored package `git-interactive-rebase-tool v2.1.0` is already installed, use --force to override"
    ],
    "stdout": "",
    "stdout_lines": []
}

TASK [community.general.cargo] *************************************************
task path: /home/ubuntu/example_playbook.yaml:7
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
<127.0.0.1> EXEC /bin/sh -c 'echo ~ubuntu && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ubuntu/.ansible/tmp `"&& mkdir "` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349993.6816304-8418-139445127205285 `" && echo ansible-tmp-1642349993.6816304-8418-139445127205285="` echo /home/ubuntu/.ansible/tmp/ansible-tmp-1642349993.6816304-8418-139445127205285 `" ) && sleep 0'
Using module file /home/ubuntu/ans/lib/python3.8/site-packages/ansible_collections/community/general/plugins/modules/cargo.py
<127.0.0.1> PUT /home/ubuntu/.ansible/tmp/ansible-local-82645tywg09a/tmp9xhl4rfc TO /home/ubuntu/.ansible/tmp/ansible-tmp-1642349993.6816304-8418-139445127205285/AnsiballZ_cargo.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1642349993.6816304-8418-139445127205285/ /home/ubuntu/.ansible/tmp/ansible-tmp-1642349993.6816304-8418-139445127205285/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/ubuntu/ans/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1642349993.6816304-8418-139445127205285/AnsiballZ_cargo.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ubuntu/.ansible/tmp/ansible-tmp-1642349993.6816304-8418-139445127205285/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "name": [
                "exa"
            ],
            "path": null,
            "state": "present",
            "version": null
        }
    },
    "stderr": null,
    "stderr_lines": [],
    "stdout": null,
    "stdout_lines": []
}
META: ran handlers
META: ran handlers

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    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/packaging/language/cargo.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/packaging/language/cargo.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 @radek-sprta
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Looking at the package names, maybe this has something to do with them having a dash in them?

Changing the regular expression https://github.com/ansible-collections/community.general/blob/main/plugins/modules/packaging/language/cargo.py#L115 to `package_regex = re.compile(r"^([\w-]+) v(.+):$")` seems to fix the problem.

Resolving patch:
diff --git a/plugins/modules/packaging/language/cargo.py b/plugins/modules/packaging/language/cargo.py
--- a/plugins/modules/packaging/language/cargo.py
+++ b/plugins/modules/packaging/language/cargo.py
@@ -112,7 +112,7 @@ def get_installed(self):
         cmd = ["install", "--list"]
         data, dummy = self._exec(cmd, True, False, False)
 
-        package_regex = re.compile(r"^(\w+) v(.+):$")
+        package_regex = re.compile(r"^([\w\-]+) v(.+):$")
         installed = {}
         for line in data.splitlines():
             package_info = package_regex.match(line)
@@ -136,11 +136,11 @@ def is_outdated(self, name):
         installed_version = self.get_installed().get(name)
 
         cmd = ["search", name, "--limit", "1"]
-        data = self._exec(cmd, True, False, False)
+        data, dummy = self._exec(cmd, True, False, False)
 
         match = re.search(r'"(.+)"', data)
         if match:
-            latest_version = match[1]
+            latest_version = match.group(1)
 
         return installed_version != latest_version
 


Test patch:
diff --git a/tests/integration/targets/cargo/tasks/test_version.yml b/tests/integration/targets/cargo/tasks/test_version.yml
--- a/tests/integration/targets/cargo/tasks/test_version.yml
+++ b/tests/integration/targets/cargo/tasks/test_version.yml
@@ -5,21 +5,42 @@
     version: 0.1.0
   register: install_helloworld_010
 
+- name: Install application helloworld-yliu 0.1.0 (idempotent)
+  community.general.cargo:
+    name: helloworld-yliu
+    version: 0.1.0
+  register: install_helloworld_010_idem
+
 - name: Upgrade helloworld-yliu 0.1.0
   community.general.cargo:
     name: helloworld-yliu
     state: latest
   register: upgrade_helloworld_010
 
+- name: Upgrade helloworld-yliu 0.1.0 (idempotent)
+  community.general.cargo:
+    name: helloworld-yliu
+    state: latest
+  register: upgrade_helloworld_010_idem
+
 - name: Downgrade helloworld-yliu 0.1.0
   community.general.cargo:
     name: helloworld-yliu
     version: 0.1.0
   register: downgrade_helloworld_010
 
-- name: Check assertions helloworld-yliu 0.1.0
+- name: Downgrade helloworld-yliu 0.1.0 (idempotent)
+  community.general.cargo:
+    name: helloworld-yliu
+    version: 0.1.0
+  register: downgrade_helloworld_010_idem
+
+- name: Check assertions helloworld-yliu
   assert:
     that:
         - install_helloworld_010 is changed
+        - install_helloworld_010_idem is not changed
         - upgrade_helloworld_010 is changed
+        - upgrade_helloworld_010_idem is not changed
         - downgrade_helloworld_010 is changed
+        - downgrade_helloworld_010_idem is not changed