community.general.cargo module – Manage Rust packages with cargo

Note

This module is part of the community.general collection (version 10.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.cargo.

New in community.general 4.3.0

Synopsis

  • Manage Rust packages with cargo.

Requirements

The below requirements are needed on the host that executes this module.

  • cargo installed

Parameters

Parameter

Comments

directory

path

added in community.general 9.1.0

Path to the source directory to install the Rust package from.

This is only used when installing packages.

executable

path

added in community.general 7.5.0

Path to the cargo installed in the system.

If not specified, the module will look cargo in PATH.

locked

boolean

added in community.general 7.5.0

Install with locked dependencies.

This is only used when installing packages.

Choices:

  • false ← (default)

  • true

name

list / elements=string / required

The name of a Rust package to install.

path

path

-> The base path where to install the Rust packages. Cargo automatically appends /bin. In other words, /usr/local will become /usr/local/bin.

state

string

The state of the Rust package.

Choices:

  • "present" ← (default)

  • "absent"

  • "latest"

version

string

-> The version to install. If name contains multiple values, the module will try to install all of them in this version.

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Examples

- name: Install "ludusavi" Rust package
  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
    version: '0.10.0'

- name: Install "ludusavi" Rust package to global location
  community.general.cargo:
    name: ludusavi
    path: /usr/local

- name: Remove "ludusavi" Rust package
  community.general.cargo:
    name: ludusavi
    state: absent

- name: Update "ludusavi" Rust package its latest version
  community.general.cargo:
    name: ludusavi
    state: latest

- name: Install "ludusavi" Rust package from source directory
  community.general.cargo:
    name: ludusavi
    directory: /path/to/ludusavi/source

Authors

  • Radek Sprta (@radek-sprta)