Enum Module

Source
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.

Fields

§dest: String
§

Package

Package module - manages software packages

Cross-platform package management that works with various package managers.

Fields

§name: String
§

Service

Service module - manages system services

Controls service state (start, stop, restart, reload).

Fields

§name: String
§

File

File module - manages files and directories

Creates, modifies, or removes files and directories with specified attributes.

Fields

§path: String
§

Template

Template module - processes Jinja2 templates

Renders Jinja2 templates and copies them to remote hosts.

Fields

§dest: String
§

User

User module - manages user accounts

Creates, modifies, or removes user accounts.

Fields

§name: String
§

Group

Group module - manages user groups

Creates, modifies, or removes user groups.

Fields

§name: String
§

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.

Fields

§dest: String
§

Synchronize

Synchronize module - synchronizes files and directories

Uses rsync to efficiently synchronize files between hosts.

Fields

§dest: String
§

Git

Git module - manages Git repositories

Clones, updates, or manages Git repositories.

Fields

§repo: String
§dest: String
§

Cron

Cron module - manages cron jobs

Creates, modifies, or removes cron jobs.

Fields

§name: String
§

Mount

Mount module - manages filesystem mounts

Mounts, unmounts, or manages filesystem mount points.

Fields

§path: String
§fstype: String
§

Systemd

Systemd module - manages systemd services

Controls systemd services with additional systemd-specific features.

Fields

§name: String
§

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");

Fields

§name: String
§args: String

Implementations§

Source§

impl Module

Source

pub fn to_args(&self) -> Vec<String>

Convert module to command line arguments

Source

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.

Source

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");
Source

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");
Source

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");
Source

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);
Source

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);
Source

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);
Source

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");
Source

pub fn user(name: impl Into<String>, state: UserState) -> Self

Create a user module

Source

pub fn group(name: impl Into<String>, state: GroupState) -> Self

Create a group module

Source

pub fn raw(command: impl Into<String>) -> Self

Create a raw module

Source

pub fn fetch(src: impl Into<String>, dest: impl Into<String>) -> Self

Create a fetch module

Source

pub fn synchronize(src: impl Into<String>, dest: impl Into<String>) -> Self

Create a synchronize module

Source

pub fn git(repo: impl Into<String>, dest: impl Into<String>) -> Self

Create a git module

Source

pub fn cron(name: impl Into<String>, job: impl Into<String>) -> Self

Create a cron module

Source

pub fn mount( path: impl Into<String>, src: impl Into<String>, fstype: impl Into<String>, ) -> Self

Create a mount module

Source

pub fn systemd(name: impl Into<String>, state: ServiceState) -> Self

Create a systemd module

Source

pub fn other(name: impl Into<String>, args: impl Into<String>) -> Self

Create a custom module

Trait Implementations§

Source§

impl Clone for Module

Source§

fn clone(&self) -> Module

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Module

Source§

fn default() -> Module

Returns the “default value” for a type. Read more
Source§

impl Display for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Module

Source§

fn eq(&self, other: &Module) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Module

Auto Trait Implementations§

§

impl Freeze for Module

§

impl RefUnwindSafe for Module

§

impl Send for Module

§

impl Sync for Module

§

impl Unpin for Module

§

impl UnwindSafe for Module

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.