Skip to main content

DefaultsBuilder

Struct DefaultsBuilder 

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

Builder for constructing Defaults instances.

This builder provides a fluent interface for creating inventory defaults with optional configuration fields. All fields start as None and can be set individually using the builder methods before calling build() to create the final Defaults instance.

Defaults define base configuration values that apply to all hosts and groups in the inventory unless overridden at the group or host level. This allows for centralized management of common connection parameters and data.

Unlike Host and Group, defaults do not support groups membership.

§Fields

  • hostname - Optional default hostname or IP address. Applied to hosts/groups that don’t specify their own hostname.

  • port - Optional default port number for connections. Applied to hosts/groups that don’t specify their own port.

  • username - Optional default username for authentication. Applied to hosts/groups that don’t specify their own username.

  • password - Optional default password for authentication. Applied to hosts/groups that don’t specify their own password.

  • platform - Optional default platform identifier (e.g., “linux”, “cisco_ios”). Applied to hosts/groups that don’t specify their own platform.

  • data - Optional arbitrary JSON data that applies to all hosts/groups by default. Can be overridden or merged at the group or host level.

  • connection_options - Optional map of connection-specific overrides keyed by connection plugin name. Allows per-connection-plugin-name customization of default parameters.

§Examples

let defaults = Defaults::builder()
    .username("admin")
    .port(22)
    .platform("linux")
    .build();

assert_eq!(defaults.username(), Some("admin"));
assert_eq!(defaults.port(), Some(22));

Implementations§

Source§

impl DefaultsBuilder

Source

pub fn new() -> Self

Source

pub fn hostname<S>(self, hostname: S) -> Self
where S: Into<String>,

Source

pub fn port(self, port: u16) -> Self

Source

pub fn username<S>(self, username: S) -> Self
where S: Into<String>,

Source

pub fn password<S>(self, password: S) -> Self
where S: Into<String>,

Source

pub fn platform<S>(self, platform: S) -> Self
where S: Into<String>,

Source

pub fn data(self, data: Data) -> Self

Source

pub fn connection_options<S>(self, name: S, options: ConnectionOptions) -> Self
where S: Into<String>,

Adds or updates connection-specific options for defaults.

§Parameters
  • name - A string-like value identifying the connection plugin name (e.g., “ssh”, “netconf”).
  • options - A ConnectionOptions instance containing connection-specific configuration.
§Returns

Returns Self with the connection options updated, allowing for method chaining. If no connection options map exists, one is created before inserting the new options.

Source

pub fn build(self) -> Defaults

Trait Implementations§

Source§

impl Default for DefaultsBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.