Struct AnsibleConfig

Source
pub struct AnsibleConfig { /* private fields */ }
Expand description

Ansible configuration management utility.

The AnsibleConfig struct provides a comprehensive interface for querying and managing Ansible configuration settings. It supports listing, dumping, viewing, initializing, and validating configuration files.

§Examples

§Basic Configuration Queries

use ansible::AnsibleConfig;

let mut config = AnsibleConfig::new();

// List all configuration options
let config_list = config.list()?;
println!("Configuration: {}", config_list);

// Dump current configuration
let config_dump = config.dump()?;
println!("Config dump: {}", config_dump);

§Formatted Output

use ansible::{AnsibleConfig, ConfigFormat};

let mut config = AnsibleConfig::new();
config.set_format(ConfigFormat::Json);

// Get configuration in JSON format
let json_config = config.dump()?;
println!("JSON config: {}", json_config);

§Plugin-Specific Configuration

use ansible::{AnsibleConfig, PluginType};

let mut config = AnsibleConfig::new();
config.set_plugin_type(PluginType::Callback);

// List only callback plugin configuration
let callback_config = config.list()?;
println!("Callback plugins: {}", callback_config);

§Configuration File Management

use ansible::AnsibleConfig;

let mut config = AnsibleConfig::new();

// Initialize a new configuration file
config.init()?;

// Validate existing configuration
config.validate()?;

// View specific configuration file
config.set_config_file("custom.cfg");
let content = config.view()?;

Implementations§

Source§

impl AnsibleConfig

Source

pub fn new() -> Self

Create a new AnsibleConfig instance

Source

pub fn set_config_file(&mut self, file_path: impl Into<String>) -> &mut Self

Set the configuration file path

Source

pub fn set_format(&mut self, format: ConfigFormat) -> &mut Self

Set the output format for configuration commands.

This method sets the format for configuration output.

§Examples
use ansible::{AnsibleConfig, ConfigFormat};

let mut config = AnsibleConfig::new();
config.set_format(ConfigFormat::Json);
Source

pub fn set_plugin_type(&mut self, plugin_type: PluginType) -> &mut Self

Set the plugin type filter.

This method filters configuration to a specific plugin type.

§Examples
use ansible::{AnsibleConfig, PluginType};

let mut config = AnsibleConfig::new();
config.set_plugin_type(PluginType::Callback);
Source

pub fn arg(&mut self, arg: impl Into<String>) -> &mut Self

Add a custom argument

Source

pub fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple arguments

Source

pub fn set_system_envs(&mut self) -> &mut Self

Set environment variables from the system

Source

pub fn add_env( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self

Add an environment variable

Source

pub fn list(&self) -> Result<String>

List all available configuration options

Source

pub fn list_with_format(&self, format: ConfigFormat) -> Result<String>

List configuration options with specific format

Source

pub fn dump(&self) -> Result<String>

Show current configuration settings

Source

pub fn dump_with_format(&self, format: ConfigFormat) -> Result<String>

Show current configuration settings with specific format

Source

pub fn dump_changed_only(&self) -> Result<String>

Show only changed configuration settings

Source

pub fn view(&self) -> Result<String>

View the current configuration file

Source

pub fn init(&self) -> Result<String>

Initialize a new configuration file

Source

pub fn init_with_format(&self, format: ConfigFormat) -> Result<String>

Initialize a new configuration file with specific format

Source

pub fn init_disabled(&self) -> Result<String>

Initialize a configuration file with all options disabled (commented out)

Source

pub fn validate(&self) -> Result<String>

Validate the configuration file

Source

pub fn validate_with_format(&self, format: ConfigFormat) -> Result<String>

Validate the configuration file with specific format

Source

pub fn verbose(&mut self) -> &mut Self

Enable verbose output

Source

pub fn verbosity(&mut self, level: u8) -> &mut Self

Set multiple levels of verbosity

Source

pub fn get_config(&self) -> &CommandConfig

Get a reference to the command configuration (for testing)

Trait Implementations§

Source§

impl Clone for AnsibleConfig

Source§

fn clone(&self) -> AnsibleConfig

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 AnsibleConfig

Source§

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

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

impl Default for AnsibleConfig

Source§

fn default() -> Self

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

impl Display for AnsibleConfig

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.