-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_vm_ansible.tf
82 lines (73 loc) · 2.78 KB
/
10_vm_ansible.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// NOTE: Step 10 is to create my Ansible Controller Machine
locals {
virtual_machine_name_ansible = "${var.ansible}"
}
resource "azurerm_network_interface" "ansible" {
name = "${var.ansible}-nic"
location = "${var.azlocation}"
resource_group_name = "${var.RG_Network}"
internal_dns_name_label = "${local.virtual_machine_name_ansible}"
network_security_group_id = "${azurerm_network_security_group.Default.id}"
depends_on = ["azurerm_subnet.Server"]
ip_configuration {
name = "ansible"
subnet_id = "${azurerm_subnet.Server.id}"
private_ip_address_allocation = "static"
private_ip_address = "172.31.2.21"
public_ip_address_id = "${azurerm_public_ip.ansible.id}"
}
}
resource "azurerm_public_ip" "ansible" {
name = "${var.ansible}-pip"
location = "${var.azlocation}"
resource_group_name = "${var.RG_Network}"
public_ip_address_allocation = "Dynamic"
depends_on = ["azurerm_subnet.Server"]
}
resource "azurerm_virtual_machine" "ansible" {
name = "${local.virtual_machine_name_ansible}"
location = "${var.azlocation}"
resource_group_name = "${var.RG_Compute}"
vm_size = "Standard_D2s_v3"
network_interface_ids = ["${element(azurerm_network_interface.ansible.*.id, count.index)}"]
delete_os_disk_on_termination = true
depends_on = ["azurerm_network_interface.ansible"]
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "${var.ansible}-root"
caching = "ReadWrite"
create_option = "FromImage"
vhd_uri = "${azurerm_storage_account.storlrs.primary_blob_endpoint}vhds/${var.ansible}-root.vhd"
}
boot_diagnostics {
enabled = true
storage_uri = "${azurerm_storage_account.storlrsdiag.primary_blob_endpoint}"
}
os_profile {
computer_name = "${var.ansible}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
}
os_profile_linux_config {
disable_password_authentication = false
}
provisioner "remote-exec" {
connection {
user = "${var.admin_username}"
password = "${var.admin_password}"
}
inline = [
"sudo apt-add-repository ppa:ansible/ansible -y",
"sudo apt-get update -y",
"sudo apt-get install ansible -y",
"sudo apt-get upgrade -y",
"sudo apt-get install htop -y",
"sudo reboot",
]
}
}