Rust toolchain installation and configuration via rustup with cargo support.
The Rust role installs the complete Rust programming language toolchain using rustup, the official Rust toolchain installer. It provides a secure, up-to-date Rust development environment with cargo package manager and essential components.
- Ubuntu 20.04 LTS or later
- Ansible 2.12 or later
- Common role (automatically included as dependency)
- Internet connectivity for rustup installation
The following variables can be set in defaults/main.yml:
# Rust toolchain configuration
rust_toolchain: "stable"
rust_profile: "default"
# Rustup configuration
rustup_url: "https://sh.rustup.rs"
rustup_checksum: "expected_checksum_here"
# Components to install
rust_components:
- rustfmt
- clippy
- rust-src
# User configuration
target_user: "{{ ansible_user }}"
rust_home: "{{ ansible_user_dir }}/.cargo"rust_toolchain: Rust toolchain to install (stable, beta, nightly, or specific version)rust_profile: Installation profile (minimal, default, complete)rustup_url: URL for rustup installation scriptrustup_checksum: Expected checksum for security validationrust_components: Additional Rust components to installtarget_user: The user for which Rust is being configuredrust_home: Cargo home directory location
common: Base system setup and essential packages
---
- hosts: servers
become: yes
roles:
- common
- rust- Secure Installation: Downloads and validates rustup installer with checksum verification
- Toolchain Management: Configures specified Rust toolchain (stable by default)
- Component Installation: Installs essential Rust components (rustfmt, clippy, rust-src)
- Cargo Configuration: Sets up cargo package manager and environment
- User Environment: Configures Rust environment for specified user
- Path Integration: Ensures cargo binaries are available in PATH
The role includes several security features:
- Checksum Validation: Verifies rustup installer integrity
- User-level Installation: Installs Rust in user space, not system-wide
- Official Sources: Downloads only from official Rust infrastructure
- Non-root Execution: Rust installation runs as target user
You can customize the Rust installation by overriding variables:
# Install nightly toolchain
rust_toolchain: "nightly"
# Minimal installation
rust_profile: "minimal"
# Additional components
rust_components:
- rustfmt
- clippy
- rust-src
- rust-analyzerThe role includes validation to ensure:
- Rust toolchain is properly installed
- Cargo is available and functional
- Components are installed correctly
- Environment variables are set
MIT
Development Team - Internal Use