[PR #7352/0ca07b0b backport][stable-7] Add executable option to cargo (#7357)

Add `executable` option to cargo (#7352)

* Add `executable` option to cargo

Add `executable` option to cargo to make the module easier to use with
cargo installed by rustup.

* Add changelog fragment

* Add license to integration test

* Do not test on CentOS 6

CentOS 6 cannot even validate the certificate in https://sh.rustup.rs.

* Fix condition to skip tests on CentOS 6

* Add version_added to path

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/cargo.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* shell → command

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 0ca07b0b05)

Co-authored-by: radek-sprta <mail@radeksprta.eu>
This commit is contained in:
patchback[bot] 2023-10-06 07:54:16 +02:00 committed by GitHub
parent 3cb9b0fa91
commit de38d23bdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 6 deletions

View file

@ -25,6 +25,12 @@ attributes:
diff_mode:
support: none
options:
executable:
description:
- Path to the C(cargo) installed in the system.
- If not specified, the module will look C(cargo) in E(PATH).
type: path
version_added: 7.5.0
name:
description:
- The name of a Rust package to install.
@ -60,7 +66,7 @@ options:
default: present
choices: [ "present", "absent", "latest" ]
requirements:
- cargo installed in bin path (recommended /usr/local/bin)
- cargo installed
"""
EXAMPLES = r"""
@ -103,14 +109,13 @@ from ansible.module_utils.basic import AnsibleModule
class Cargo(object):
def __init__(self, module, **kwargs):
self.module = module
self.executable = [kwargs["executable"] or module.get_bin_path("cargo", True)]
self.name = kwargs["name"]
self.path = kwargs["path"]
self.state = kwargs["state"]
self.version = kwargs["version"]
self.locked = kwargs["locked"]
self.executable = [module.get_bin_path("cargo", True)]
@property
def path(self):
return self._path
@ -176,6 +181,7 @@ class Cargo(object):
def main():
arg_spec = dict(
executable=dict(default=None, type="path"),
name=dict(required=True, type="list", elements="str"),
path=dict(default=None, type="path"),
state=dict(default="present", choices=["present", "absent", "latest"]),
@ -185,10 +191,8 @@ def main():
module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True)
name = module.params["name"]
path = module.params["path"]
state = module.params["state"]
version = module.params["version"]
locked = module.params["locked"]
if not name:
module.fail_json(msg="Package name must be specified")
@ -198,7 +202,7 @@ def main():
LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C"
)
cargo = Cargo(module, name=name, path=path, state=state, version=version, locked=locked)
cargo = Cargo(module, **module.params)
changed, out, err = False, None, None
installed_packages = cargo.get_installed()
if state == "present":