Skip to content

Commit

Permalink
wip: reorganize templates
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Nov 8, 2023
1 parent 8cd797b commit 69a1abb
Show file tree
Hide file tree
Showing 35 changed files with 372 additions and 561 deletions.
311 changes: 0 additions & 311 deletions goldboot/src/provisioners.rs

This file was deleted.

70 changes: 70 additions & 0 deletions goldboot/src/provisioners/ansible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#[derive(Clone, Serialize, Deserialize, Validate, Debug)]
pub struct AnsibleProvisioners {
pub ansible: Vec<AnsibleProvisioner>,
}

/// This provisioner runs an Ansible playbook on the image remotely.
#[derive(Clone, Serialize, Deserialize, Validate, Debug)]
pub struct AnsibleProvisioner {
/// The playbook file
pub playbook: String,

/// The inventory file
pub inventory: Option<String>,

/// Overrides the default run order
pub order: Option<usize>,
}

impl AnsibleProvisioner {
pub fn run(&self, ssh: &mut SshConnection) -> Result<(), Box<dyn Error>> {
info!("Running ansible provisioner");

if let Some(code) = Command::new("ansible-playbook")
.arg("--ssh-common-args")
.arg("-o StrictHostKeyChecking=no")
.arg("-e")
.arg(format!("ansible_port={}", ssh.port))
.arg("-e")
.arg(format!("ansible_user={}", ssh.username))
.arg("-e")
.arg(format!("ansible_ssh_pass={}", ssh.password))
.arg("-e")
.arg("ansible_connection=ssh")
.arg(&self.playbook)
.status()
.expect("Failed to launch ansible-playbook")
.code()
{
if code != 0 {
bail!("Provisioning failed");
}
}

Ok(())
}
}

impl PromptMut for AnsibleProvisioner {
fn prompt(
&mut self,
config: &BuildConfig,
theme: &ColorfulTheme,
) -> Result<(), Box<dyn Error>> {
self.playbook = dialoguer::Input::with_theme(theme)
.with_prompt("Enter the playbook path relative to the current directory")
.interact()?;

if !Path::new(&self.playbook).exists() {
if !dialoguer::Confirm::with_theme(theme)
.with_prompt("The path does not exist. Add anyway?")
.interact()?
{
bail!("The playbook did not exist");
}
}

self.validate()?;
Ok(())
}
}
1 change: 1 addition & 0 deletions goldboot/src/provisioners/dns_resolver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct DnsResolverProvisioner {}
Loading

0 comments on commit 69a1abb

Please sign in to comment.