-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible-v2.tf
51 lines (40 loc) · 1.75 KB
/
ansible-v2.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
resource "null_resource" "ansible-provision" {
depends_on = ["aws_instance.ec2-jenkins"]
triggers {
key = "${uuid()}"
}
provisioner "local-exec" {
command = "echo \"[jenkins]\n${aws_instance.ec2-jenkins.public_dns} ansible_ssh_host=${aws_instance.ec2-jenkins.public_ip}\n\" > ansible/inventory/${var.ANSIBLE_INVENTORY_NAME}"
}
provisioner "local-exec" {
command = "echo \"\n[openvpn]\" >> ansible/inventory/${var.ANSIBLE_INVENTORY_NAME}"
}
provisioner "local-exec" {
command = "echo \"${join("\n",formatlist("%s ansible_ssh_host=%s", aws_instance.ec2-openvpn.*.public_dns, aws_instance.ec2-openvpn.*.public_ip))}\" >> ansible/inventory/${var.ANSIBLE_INVENTORY_NAME}"
}
provisioner "local-exec" {
command = "echo \"\n[all:vars]\" >> ansible/inventory/${var.ANSIBLE_INVENTORY_NAME}"
}
provisioner "local-exec" {
command = "echo \"${format("ansible_ssh_user=%s", var.INSTANCE_USERNAME)}\" >> ansible/inventory/${var.ANSIBLE_INVENTORY_NAME}"
}
provisioner "local-exec" {
command = "echo \"${format("ansible_python_interpreter=\"%s\"", var.ANSIBLE_PYTHON_PATH)}\" >> ansible/inventory/${var.ANSIBLE_INVENTORY_NAME}"
}
}
resource "null_resource" "ec2-jenkins" {
depends_on = [
"aws_instance.ec2-jenkins",
"aws_instance.ec2-openvpn",
"null_resource.ansible-provision",
]
triggers {
key = "${uuid()}"
}
provisioner "local-exec" {
command = "cd ansible && ansible-playbook -i inventory/${var.ANSIBLE_INVENTORY_NAME} -l jenkins --private-key=../${var.PATH_TO_PRIVATE_KEY} playbooks/jenkins.yml"
}
provisioner "local-exec" {
command = "cd ansible && ansible-playbook -i inventory/${var.ANSIBLE_INVENTORY_NAME} -l openvpn --private-key=../${var.PATH_TO_PRIVATE_KEY} playbooks/openvpn.yml"
}
}