Skip to content

Commit

Permalink
Add support for ansible playbooks for bootstrapping #43
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Papke committed Nov 7, 2018
1 parent e4cd68e commit 1838105
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
5 changes: 4 additions & 1 deletion modules/cloud-portal-server-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@
<!-- install ansible -->
<run>apt-get install -y --no-install-recommends ansible</run>

<!-- install ansible pysphere package -->
<!-- install ansible pysphere module -->
<run>pip install pysphere</run>

<!-- install ansible pywinrm module -->
<run>pip install pywinrm</run>

<!-- clear apt cache -->
<run>apt-get clean</run>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class TerraformService extends ProvisionerService {

public static final String PREFIX = "terraform";

private static final String ANSIBLE_USERNAME = "ansible_user";
private static final String ANSIBLE_PASSWORD = "ansible_password"; // NOSONAR
private static final String ANSIBLE_SSH_USER = "ansible_ssh_user";
private static final String ANSIBLE_SSH_PASS = "ansible_ssh_pass"; // NOSONAR
private static final String ANSIBLE_SUDO_PASS = "ansible_sudo_pass"; // NOSONAR
Expand Down Expand Up @@ -127,7 +129,9 @@ protected void prepare(UseCase useCase, String action, Credentials credentials,
credentialsMap.put(ANSIBLE_SSH_PASS, credentialsMap.get(ESXI_PASSWORD));
}
else {
credentialsMap.put(ANSIBLE_USERNAME, (String) variableMap.get(USERNAME));
credentialsMap.put(ANSIBLE_SSH_USER, (String) variableMap.get(USERNAME));
credentialsMap.put(ANSIBLE_PASSWORD, (String) variableMap.get(PASSWORD));
credentialsMap.put(ANSIBLE_SSH_PASS, (String) variableMap.get(PASSWORD));
credentialsMap.put(ANSIBLE_SUDO_PASS, (String) variableMap.get(PASSWORD));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ host_key_checking = False
deprecation_warnings = False

# hide command warnings
command_warnings=False
command_warnings = False
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,32 @@ resource "null_resource" "windowsprovisioning" {

provisioner "remote-exec" {
inline = [
"Powershell.exe -ExecutionPolicy Unrestricted -File ${local.windows_prepare_script_path} ${var.random_id}",
"Powershell.exe -ExecutionPolicy Unrestricted -File ${local.windows_user_script_path}",
"Powershell.exe -ExecutionPolicy Unrestricted -File ${local.windows_prepare_script_path} ${var.random_id}"
]
}

provisioner "remote-exec" {
inline = [
"Powershell.exe -ExecutionPolicy Unrestricted -File ${local.windows_user_script_path}"
]
}

provisioner "local-exec" {
command = "ansible-galaxy install -c -r ${var.ansible_requirements_file}"
on_failure = "continue"
}

provisioner "local-exec" {
command = "ansible-playbook -i ${vsphere_virtual_machine.windows.guest_ip_addresses.0}, -e ansible_port='5985' -e ansible_connection='winrm' -e \"@parameters.yml\" ${var.ansible_playbook_file}"
on_failure = "continue"
}

provisioner "remote-exec" {
inline = [
"Powershell.exe -ExecutionPolicy Unrestricted -File ${local.windows_cleanup_script_path}",
"Powershell.exe -ExecutionPolicy Unrestricted -Command Remove-Item ${local.windows_script_folder_path} -Force -Recurse"
]
}
}

depends_on = ["vsphere_virtual_machine.windows"]
}

0 comments on commit 1838105

Please sign in to comment.