-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
372 additions
and
561 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub struct DnsResolverProvisioner {} |
Oops, something went wrong.