-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.tf
72 lines (60 loc) · 1.42 KB
/
machine.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
# Script Provisiona Ambiente Cluster Cloudera com 3 VMs
# Autor: Michael Christian
# github: mchristian279
#Provider
provider "libvirt" {
uri = "qemu:///system"
}
#Imagem
resource "libvirt_volume" "os_image" {
name = "os_image"
pool = "Dados"
source = var.disk_img
}
#Volume
resource "libvirt_volume" "volume" {
name = "cloudera-${count.index}"
pool = "Dados"
base_volume_id = libvirt_volume.os_image.id
count = var.instance_count
}
#Rede
resource "libvirt_network" "vm_network" {
name = var.vm_network_name
addresses = ["${var.vm_network_addresses}"]
domain = var.domain_name
mode = "nat"
dhcp {
enabled = false
}
dns {
local_only = true
}
autostart = true
}
#VM
resource "libvirt_domain" "domain" {
name = "cloudera-${count.index}"
memory = "8024"
vcpu = "2"
network_interface {
network_id = libvirt_network.vm_network.id
hostname = "cloudera-${count.index}"
addresses = ["${var.vm_addresses[count.index]}"]
wait_for_lease = true
}
disk {
volume_id = libvirt_volume.volume[count.index].id
}
count = var.instance_count
}
#Ansible
resource "null_resource" "ansible" {
triggers = {
key = "${uuid()}"
}
depends_on = [libvirt_domain.domain]
provisioner "local-exec" {
command = "ansible-playbook -i inventory.hosts -u root playbook.yml --private-key=./key/id_rsa.pem -u root"
}
}