summaryrefslogtreecommitdiffstats
path: root/ansible_collections/community/general/plugins/modules/cargo.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:22 +0000
commit38b7c80217c4e72b1d8988eb1e60bb6e77334114 (patch)
tree356e9fd3762877d07cde52d21e77070aeff7e789 /ansible_collections/community/general/plugins/modules/cargo.py
parentAdding upstream version 7.7.0+dfsg. (diff)
downloadansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.tar.xz
ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.zip
Adding upstream version 9.4.0+dfsg.upstream/9.4.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/general/plugins/modules/cargo.py')
-rw-r--r--ansible_collections/community/general/plugins/modules/cargo.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/ansible_collections/community/general/plugins/modules/cargo.py b/ansible_collections/community/general/plugins/modules/cargo.py
index 24be43741..ba9c05ed7 100644
--- a/ansible_collections/community/general/plugins/modules/cargo.py
+++ b/ansible_collections/community/general/plugins/modules/cargo.py
@@ -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.
@@ -35,15 +41,23 @@ options:
description:
->
The base path where to install the Rust packages. Cargo automatically appends
- C(/bin). In other words, C(/usr/local) will become C(/usr/local/bin).
+ V(/bin). In other words, V(/usr/local) will become V(/usr/local/bin).
type: path
version:
description:
->
- The version to install. If I(name) contains multiple values, the module will
+ The version to install. If O(name) contains multiple values, the module will
try to install all of them in this version.
type: str
required: false
+ locked:
+ description:
+ - Install with locked dependencies.
+ - This is only used when installing packages.
+ required: false
+ type: bool
+ default: false
+ version_added: 7.5.0
state:
description:
- The state of the Rust package.
@@ -52,7 +66,7 @@ options:
default: present
choices: [ "present", "absent", "latest" ]
requirements:
- - cargo installed in bin path (recommended /usr/local/bin)
+ - cargo installed
"""
EXAMPLES = r"""
@@ -60,6 +74,11 @@ EXAMPLES = r"""
community.general.cargo:
name: ludusavi
+- name: Install "ludusavi" Rust package with locked dependencies
+ community.general.cargo:
+ name: ludusavi
+ locked: true
+
- name: Install "ludusavi" Rust package in version 0.10.0
community.general.cargo:
name: ludusavi
@@ -90,12 +109,12 @@ 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.executable = [module.get_bin_path("cargo", True)]
+ self.locked = kwargs["locked"]
@property
def path(self):
@@ -118,6 +137,10 @@ class Cargo(object):
def get_installed(self):
cmd = ["install", "--list"]
+ if self.path:
+ cmd.append("--root")
+ cmd.append(self.path)
+
data, dummy = self._exec(cmd, True, False, False)
package_regex = re.compile(r"^([\w\-]+) v(.+):$")
@@ -132,6 +155,8 @@ class Cargo(object):
def install(self, packages=None):
cmd = ["install"]
cmd.extend(packages or self.name)
+ if self.locked:
+ cmd.append("--locked")
if self.path:
cmd.append("--root")
cmd.append(self.path)
@@ -160,15 +185,16 @@ 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"]),
version=dict(default=None, type="str"),
+ locked=dict(default=False, type="bool"),
)
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"]
@@ -180,7 +206,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)
+ cargo = Cargo(module, **module.params)
changed, out, err = False, None, None
installed_packages = cargo.get_installed()
if state == "present":