pub struct AnsibleTemplateRenderingService { /* private fields */ }Expand description
Service for rendering Ansible templates with runtime configuration
This service encapsulates the logic for rendering Ansible inventory and configuration templates. It’s designed to be shared across command handlers that need to prepare Ansible files (e.g., Provision, Register).
§Design
The service follows dependency injection principles:
- Dependencies (template renderer) are injected at construction time
- Runtime data (SSH credentials, IP, port) is passed to the render method
This allows the service to be configured once and reused with different runtime parameters.
Implementations§
Source§impl AnsibleTemplateRenderingService
impl AnsibleTemplateRenderingService
Sourcepub fn new(
ansible_template_renderer: Arc<AnsibleProjectGenerator>,
clock: Arc<dyn Clock>,
) -> Self
pub fn new( ansible_template_renderer: Arc<AnsibleProjectGenerator>, clock: Arc<dyn Clock>, ) -> Self
Create a new AnsibleTemplateRenderingService
§Arguments
ansible_template_renderer- The renderer for Ansible templatesclock- The clock for generating timestamps
Sourcepub fn from_paths(
templates_dir: PathBuf,
build_dir: PathBuf,
clock: Arc<dyn Clock>,
) -> Self
pub fn from_paths( templates_dir: PathBuf, build_dir: PathBuf, clock: Arc<dyn Clock>, ) -> Self
Build an AnsibleTemplateRenderingService from environment paths
This is a factory method that creates the service with all necessary dependencies based on the environment’s template and build directories.
§Arguments
templates_dir- Directory containing the source templatesbuild_dir- Directory where rendered templates will be writtenclock- The clock for generating timestamps
§Returns
Returns a configured AnsibleTemplateRenderingService ready for template rendering
§Example
use std::path::PathBuf;
use std::sync::Arc;
use torrust_tracker_deployer_lib::application::services::rendering::AnsibleTemplateRenderingService;
use torrust_tracker_deployer_lib::shared::clock::SystemClock;
let service = AnsibleTemplateRenderingService::from_paths(
PathBuf::from("templates"),
PathBuf::from("build/my-env"),
Arc::new(SystemClock),
);Sourcepub async fn render_templates(
&self,
user_inputs: &UserInputs,
instance_ip: IpAddr,
ssh_port_override: Option<u16>,
) -> Result<(), AnsibleTemplateRenderingServiceError>
pub async fn render_templates( &self, user_inputs: &UserInputs, instance_ip: IpAddr, ssh_port_override: Option<u16>, ) -> Result<(), AnsibleTemplateRenderingServiceError>
Render Ansible templates with the provided runtime configuration
This renders the Ansible inventory and configuration templates so that Ansible playbooks can be executed against the target instance.
§Arguments
user_inputs- User-provided environment configuration (SSH credentials, tracker config, etc.)instance_ip- IP address of the provisioned instance (runtime output)ssh_port_override- Optional SSH port override (takes precedence overuser_inputs.ssh_port)
§Errors
Returns AnsibleTemplateRenderingServiceError::RenderingFailed if template rendering fails.
§Example
use std::net::IpAddr;
let service = AnsibleTemplateRenderingService::from_paths(...);
service.render_templates(&user_inputs, "192.168.1.100".parse().unwrap(), None).await?;Auto Trait Implementations§
impl !RefUnwindSafe for AnsibleTemplateRenderingService
impl !UnwindSafe for AnsibleTemplateRenderingService
impl Freeze for AnsibleTemplateRenderingService
impl Send for AnsibleTemplateRenderingService
impl Sync for AnsibleTemplateRenderingService
impl Unpin for AnsibleTemplateRenderingService
impl UnsafeUnpin for AnsibleTemplateRenderingService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request