pub enum Module {
Show 21 variants
None,
Ping,
Setup,
Shell(String),
Command(String),
Script(String),
Copy {
src: String,
dest: String,
},
Package {
name: String,
state: PackageState,
},
Service {
name: String,
state: ServiceState,
},
File {
path: String,
state: FileState,
},
Template {
src: String,
dest: String,
},
User {
name: String,
state: UserState,
},
Group {
name: String,
state: GroupState,
},
Raw(String),
Fetch {
src: String,
dest: String,
},
Synchronize {
src: String,
dest: String,
},
Git {
repo: String,
dest: String,
},
Cron {
name: String,
job: String,
},
Mount {
path: String,
src: String,
fstype: String,
},
Systemd {
name: String,
state: ServiceState,
},
Other {
name: String,
args: String,
},
}
Expand description
Type-safe representation of Ansible modules with their arguments.
The Module
enum provides a type-safe way to construct Ansible modules
with their parameters. Each variant corresponds to a specific Ansible module
and includes the necessary parameters for that module.
§Examples
§Basic Modules
use ansible::Module;
// Ping module
let ping = Module::Ping;
// Shell command
let shell = Module::shell("uptime");
// Command execution
let cmd = Module::command("ls -la");
§Package Management
use ansible::{Module, PackageState};
// Install a package
let install = Module::package("nginx", PackageState::Present);
// Remove a package
let remove = Module::package("apache2", PackageState::Absent);
§File Operations
use ansible::{Module, FileState};
// Create a directory
let mkdir = Module::file("/opt/myapp", FileState::Directory);
// Copy a file
let copy = Module::copy("/local/file", "/remote/file");
§Service Management
use ansible::{Module, ServiceState};
// Start a service
let start = Module::service("nginx", ServiceState::Started);
// Stop a service
let stop = Module::systemd("apache2", ServiceState::Stopped);
Variants§
None
No module specified (default state)
Ping
Ping module - tests connectivity to remote hosts
Equivalent to ansible -m ping
Setup
Setup module - gathers facts about remote hosts
Equivalent to ansible -m setup
Shell(String)
Shell module - executes shell commands with shell processing
Supports shell features like pipes, redirects, and variables.
Use Module::command
for simple command execution.
Command(String)
Command module - executes commands without shell processing
Safer than shell module as it doesn’t process shell metacharacters.
Script(String)
Script module - executes local scripts on remote hosts
Transfers and executes a local script on the remote host.
Copy
Copy module - copies files from local to remote hosts
Supports file copying with permission and ownership management.
Package
Package module - manages software packages
Cross-platform package management that works with various package managers.
Service
Service module - manages system services
Controls service state (start, stop, restart, reload).
File
File module - manages files and directories
Creates, modifies, or removes files and directories with specified attributes.
Template
Template module - processes Jinja2 templates
Renders Jinja2 templates and copies them to remote hosts.
User
User module - manages user accounts
Creates, modifies, or removes user accounts.
Group
Group module - manages user groups
Creates, modifies, or removes user groups.
Raw(String)
Raw module - executes raw commands bypassing the module system
Useful for commands that don’t work well with the command module.
Fetch
Fetch module - retrieves files from remote hosts
Downloads files from remote hosts to the local machine.
Synchronize
Synchronize module - synchronizes files and directories
Uses rsync to efficiently synchronize files between hosts.
Git
Git module - manages Git repositories
Clones, updates, or manages Git repositories.
Cron
Cron module - manages cron jobs
Creates, modifies, or removes cron jobs.
Mount
Mount module - manages filesystem mounts
Mounts, unmounts, or manages filesystem mount points.
Systemd
Systemd module - manages systemd services
Controls systemd services with additional systemd-specific features.
Other
Custom module - allows using any Ansible module
Provides access to modules not explicitly supported by this library.
§Examples
use ansible::Module;
// Use a custom module
let custom = Module::other("my_module", "param1=value1 param2=value2");
Implementations§
Source§impl Module
impl Module
Sourcepub fn shell(command: impl Into<String>) -> Self
pub fn shell(command: impl Into<String>) -> Self
Create a shell module for executing shell commands.
The shell module executes commands through the shell, allowing for shell features like pipes, redirects, and variable expansion.
§Examples
use ansible::Module;
let module = Module::shell("ps aux | grep nginx");
let module = Module::shell("echo $HOME");
§Security Note
Be careful with shell injection when using user input.
Consider using Module::command
for simple command execution.
Sourcepub fn command(command: impl Into<String>) -> Self
pub fn command(command: impl Into<String>) -> Self
Create a command module for executing commands safely.
The command module executes commands without shell processing, making it safer for user input but limiting shell features.
§Examples
use ansible::Module;
let module = Module::command("ls -la /opt");
let module = Module::command("systemctl status nginx");
Sourcepub fn script(script_path: impl Into<String>) -> Self
pub fn script(script_path: impl Into<String>) -> Self
Create a script module for executing local scripts on remote hosts.
The script is transferred to the remote host and executed there.
§Examples
use ansible::Module;
let module = Module::script("/path/to/local/script.sh");
let module = Module::script("./deploy.py");
Sourcepub fn copy(src: impl Into<String>, dest: impl Into<String>) -> Self
pub fn copy(src: impl Into<String>, dest: impl Into<String>) -> Self
Create a copy module for transferring files to remote hosts.
Copies files from the local machine to remote hosts with support for permissions, ownership, and backup options.
§Examples
use ansible::Module;
let module = Module::copy("/local/config.conf", "/etc/myapp/config.conf");
let module = Module::copy("./app.jar", "/opt/myapp/app.jar");
Sourcepub fn package(name: impl Into<String>, state: PackageState) -> Self
pub fn package(name: impl Into<String>, state: PackageState) -> Self
Create a package module for managing software packages.
The package module provides cross-platform package management that works with various package managers (apt, yum, dnf, etc.).
§Examples
use ansible::{Module, PackageState};
// Install a package
let install = Module::package("nginx", PackageState::Present);
// Remove a package
let remove = Module::package("apache2", PackageState::Absent);
// Update to latest version
let update = Module::package("curl", PackageState::Latest);
Sourcepub fn service(name: impl Into<String>, state: ServiceState) -> Self
pub fn service(name: impl Into<String>, state: ServiceState) -> Self
Create a service module for managing system services.
The service module controls service state across different service management systems (systemd, SysV init, etc.).
§Examples
use ansible::{Module, ServiceState};
// Start a service
let start = Module::service("nginx", ServiceState::Started);
// Stop a service
let stop = Module::service("apache2", ServiceState::Stopped);
// Restart a service
let restart = Module::service("mysql", ServiceState::Restarted);
Sourcepub fn file(path: impl Into<String>, state: FileState) -> Self
pub fn file(path: impl Into<String>, state: FileState) -> Self
Create a file module for managing files and directories.
The file module can create, modify, or remove files and directories with specified permissions, ownership, and other attributes.
§Examples
use ansible::{Module, FileState};
// Create a directory
let mkdir = Module::file("/opt/myapp", FileState::Directory);
// Create an empty file
let touch = Module::file("/tmp/marker", FileState::Touch);
// Remove a file
let remove = Module::file("/tmp/old_file", FileState::Absent);
Sourcepub fn template(src: impl Into<String>, dest: impl Into<String>) -> Self
pub fn template(src: impl Into<String>, dest: impl Into<String>) -> Self
Create a template module for processing Jinja2 templates.
The template module renders Jinja2 templates with variables and copies the result to remote hosts.
§Examples
use ansible::Module;
let template = Module::template("nginx.conf.j2", "/etc/nginx/nginx.conf");
let template = Module::template("app.properties.j2", "/opt/app/config/app.properties");
Sourcepub fn group(name: impl Into<String>, state: GroupState) -> Self
pub fn group(name: impl Into<String>, state: GroupState) -> Self
Create a group module
Sourcepub fn synchronize(src: impl Into<String>, dest: impl Into<String>) -> Self
pub fn synchronize(src: impl Into<String>, dest: impl Into<String>) -> Self
Create a synchronize module
Sourcepub fn mount(
path: impl Into<String>,
src: impl Into<String>,
fstype: impl Into<String>,
) -> Self
pub fn mount( path: impl Into<String>, src: impl Into<String>, fstype: impl Into<String>, ) -> Self
Create a mount module
Sourcepub fn systemd(name: impl Into<String>, state: ServiceState) -> Self
pub fn systemd(name: impl Into<String>, state: ServiceState) -> Self
Create a systemd module