pub enum AnsibleError {
Io(Error),
CommandFailed {
message: String,
exit_code: Option<i32>,
stdout: Option<String>,
stderr: Option<String>,
},
InvalidModule(String),
InvalidInventory(String),
PlaybookError(String),
EnvironmentError(String),
ConfigError(String),
UnsupportedPlatform(String),
CommandNotFound(String),
SystemRequirement(String),
Unknown,
}
Expand description
Comprehensive error types for Ansible operations.
The AnsibleError
enum provides detailed error information for different
types of failures that can occur when executing Ansible commands, managing
configurations, or working with inventories.
§Examples
§Error Handling
use ansible::{Ansible, AnsibleError};
let result = Ansible::default().ping();
match result {
Ok(output) => println!("Success: {}", output),
Err(AnsibleError::CommandFailed { message, exit_code, stdout, stderr }) => {
eprintln!("Command failed: {}", message);
if let Some(code) = exit_code {
eprintln!("Exit code: {}", code);
}
if let Some(stderr) = stderr {
eprintln!("Error output: {}", stderr);
}
}
Err(AnsibleError::UnsupportedPlatform(msg)) => {
eprintln!("Platform not supported: {}", msg);
}
Err(e) => eprintln!("Other error: {}", e),
}
§Error Construction
use ansible::AnsibleError;
// Create specific error types
let cmd_error = AnsibleError::command_failed(
"ansible ping failed",
Some(1),
Some("output".to_string()),
Some("error".to_string())
);
let platform_error = AnsibleError::unsupported_platform("Windows not supported");
Variants§
Io(Error)
I/O operation failed
CommandFailed
Ansible command execution failed
InvalidModule(String)
Invalid module configuration
InvalidInventory(String)
Invalid inventory configuration
PlaybookError(String)
Playbook parsing or execution error
EnvironmentError(String)
Environment variable error
ConfigError(String)
Configuration error
UnsupportedPlatform(String)
Unsupported platform error
CommandNotFound(String)
Command not found error
SystemRequirement(String)
System requirement not met
Unknown
Unknown error
Implementations§
Source§impl AnsibleError
impl AnsibleError
Sourcepub fn command_failed(
message: impl Into<String>,
exit_code: Option<i32>,
stdout: Option<String>,
stderr: Option<String>,
) -> Self
pub fn command_failed( message: impl Into<String>, exit_code: Option<i32>, stdout: Option<String>, stderr: Option<String>, ) -> Self
Create a command failed error with detailed information
Sourcepub fn invalid_module(message: impl Into<String>) -> Self
pub fn invalid_module(message: impl Into<String>) -> Self
Create an invalid module error
Sourcepub fn invalid_inventory(message: impl Into<String>) -> Self
pub fn invalid_inventory(message: impl Into<String>) -> Self
Create an invalid inventory error
Sourcepub fn playbook_error(message: impl Into<String>) -> Self
pub fn playbook_error(message: impl Into<String>) -> Self
Create a playbook error
Sourcepub fn environment_error(message: impl Into<String>) -> Self
pub fn environment_error(message: impl Into<String>) -> Self
Create an environment error
Sourcepub fn config_error(message: impl Into<String>) -> Self
pub fn config_error(message: impl Into<String>) -> Self
Create a configuration error
Sourcepub fn unsupported_platform(message: impl Into<String>) -> Self
pub fn unsupported_platform(message: impl Into<String>) -> Self
Create an unsupported platform error
Sourcepub fn command_not_found(message: impl Into<String>) -> Self
pub fn command_not_found(message: impl Into<String>) -> Self
Create a command not found error
Sourcepub fn system_requirement(message: impl Into<String>) -> Self
pub fn system_requirement(message: impl Into<String>) -> Self
Create a system requirement error
Sourcepub fn parsing_failed(message: impl Into<String>) -> Self
pub fn parsing_failed(message: impl Into<String>) -> Self
Create a parsing failed error