Add third domain, generate ansible toml inventory
generate ansible inventory from terraform provisioned domain add make hazelcast to run and setup hazelcast onto domain
This commit is contained in:
parent
a75f875026
commit
f70970f0e4
22
Makefile
22
Makefile
@ -14,4 +14,24 @@ get-ip:
|
|||||||
@virsh domifaddr --domain db1
|
@virsh domifaddr --domain db1
|
||||||
|
|
||||||
destroy_vm:
|
destroy_vm:
|
||||||
@terraform destroy -auto-approve -target=libvirt_domain.db1
|
@cd stack && terraform destroy --auto-approve -target=libvirt_domain.db1
|
||||||
|
|
||||||
|
destroy_all:
|
||||||
|
@cd stack && terraform destroy --auto-approve
|
||||||
|
|
||||||
|
create_all:
|
||||||
|
@cd stack && terraform apply --auto-approve
|
||||||
|
|
||||||
|
hazelcast:
|
||||||
|
cd applications/ && \
|
||||||
|
echo "create python venv workspace" && \
|
||||||
|
python3 -m venv workspace && \
|
||||||
|
source workspace/bin/activate && \
|
||||||
|
echo "install python venv and dependencies" && \
|
||||||
|
pip install --upgrade pip && \
|
||||||
|
pip install -r requirements.txt && \
|
||||||
|
echo "install ansible-galaxy dependencies" && \
|
||||||
|
ansible-galaxy install -r hazelcast/requirements.yml && \
|
||||||
|
echo "start playbook" && \
|
||||||
|
ansible-playbook -i stack_address.toml hazelcast/playbook.yml
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
data "template_file" "user_data" {
|
data "template_file" "user_data" {
|
||||||
template = "${file("${path.module}/cloud_init_user_data.yml")}"
|
template = file(format("%s/cloud_init_user_data.yml", path.module))
|
||||||
vars = {
|
vars = {
|
||||||
hostname = format("%s-%s", var.hostname, count.index)
|
hostname = format("%s-%s", var.hostname, count.index)
|
||||||
}
|
}
|
||||||
@ -7,7 +7,7 @@ data "template_file" "user_data" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data "template_file" "meta_data" {
|
data "template_file" "meta_data" {
|
||||||
template = "${file("${path.module}/cloud_init_meta_data.yml")}"
|
template = file(format("%s/cloud_init_meta_data.yml", path.module))
|
||||||
vars = {
|
vars = {
|
||||||
instance_id = count.index
|
instance_id = count.index
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ resource "libvirt_domain" "domains" {
|
|||||||
autostart = "true"
|
autostart = "true"
|
||||||
|
|
||||||
count = var.number_domain
|
count = var.number_domain
|
||||||
|
qemu_agent = true
|
||||||
|
|
||||||
boot_device {
|
boot_device {
|
||||||
dev = ["hd", "network"]
|
dev = ["hd", "network"]
|
||||||
|
@ -16,10 +16,6 @@ terraform {
|
|||||||
source = "dmacvicar/libvirt"
|
source = "dmacvicar/libvirt"
|
||||||
version = ">= 0.6.3"
|
version = ">= 0.6.3"
|
||||||
}
|
}
|
||||||
docker = {
|
|
||||||
source = "kreuzwerker/docker"
|
|
||||||
version = "2.11.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backend "etcdv3" {
|
backend "etcdv3" {
|
||||||
@ -42,7 +38,7 @@ resource "null_resource" "delay_10s" {
|
|||||||
command = "sleep 120"
|
command = "sleep 120"
|
||||||
}
|
}
|
||||||
triggers = {
|
triggers = {
|
||||||
// trigger after last domain created
|
# trigger after last domain created
|
||||||
"after" = libvirt_domain.domains[var.number_domain - 1].id
|
"after" = libvirt_domain.domains[var.number_domain - 1].id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,3 +48,17 @@ output "ip" {
|
|||||||
value = libvirt_domain.domains.*.network_interface
|
value = libvirt_domain.domains.*.network_interface
|
||||||
depends_on = [null_resource.delay_10s]
|
depends_on = [null_resource.delay_10s]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "local_file" "write_address" {
|
||||||
|
|
||||||
|
content = <<-EOT
|
||||||
|
[all]
|
||||||
|
%{ for idx, s in libvirt_domain.domains.*.network_interface.0.addresses.0 ~}
|
||||||
|
${s} index=${idx}
|
||||||
|
%{ endfor ~}
|
||||||
|
[all:vars]
|
||||||
|
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
|
||||||
|
EOT
|
||||||
|
|
||||||
|
filename = "../applications/stack_address.toml"
|
||||||
|
}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
resource "libvirt_network" "private_network" {
|
resource "libvirt_network" "private_network" {
|
||||||
name = "private"
|
name = "private"
|
||||||
mode = "nat"
|
mode = "bridge" # "nat"
|
||||||
domain = "network.local"
|
bridge = "br0" # only for bridge mode
|
||||||
addresses = ["10.17.3.0/24"]
|
# domain = "network.local" # only for nat mode
|
||||||
|
# addresses = [var.ip] # only for nat mode
|
||||||
autostart = true
|
autostart = true
|
||||||
dhcp {
|
dhcp {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
variable "ip" {
|
variable "ip" {
|
||||||
type = string
|
type = string
|
||||||
default = "10.17.3.35/"
|
default = "10.17.3.35/24"
|
||||||
description = "fixed ip address for compute"
|
description = "fixed ip address for compute"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "number_domain" {
|
variable "number_domain" {
|
||||||
type = string
|
type = string
|
||||||
default = "3"
|
default = "4"
|
||||||
description = "number of domain"
|
description = "number of domain"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,14 +28,7 @@ variable "pool_1" {
|
|||||||
description = "already created pool name, set with variable because libvirt provider dont' wotk with data resource"
|
description = "already created pool name, set with variable because libvirt provider dont' wotk with data resource"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "debian_buster_qcow2" {
|
locals {
|
||||||
type = string
|
debian_buster_qcow2 = "debian-10.7.0-with-docker.qcow2"
|
||||||
default = "debian-10.7.0-with-docker.qcow2"
|
centos7_qcow2 = "centos7.qcow2"
|
||||||
description = "already created debian vol, set with variable because libvirt provider dont' wotk with data resource"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "centos7_qcow2" {
|
|
||||||
type = string
|
|
||||||
default = "centos7.qcow2"
|
|
||||||
description = "already created centos vol, set with variable because libvirt provider dont' wotk with data resource"
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
resource "libvirt_volume" "root_centos" {
|
resource "libvirt_volume" "root_centos" {
|
||||||
name = "my-root-centos"
|
name = "my-root-centos"
|
||||||
pool = var.pool_1
|
pool = var.pool_1
|
||||||
base_volume_name = var.centos7_qcow2
|
base_volume_name = local.centos7_qcow2
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "libvirt_volume" "root_debian" {
|
resource "libvirt_volume" "root_debian" {
|
||||||
name = format("root-debian-%s", count.index)
|
name = format("root-debian-%s", count.index)
|
||||||
pool = var.pool_1
|
pool = var.pool_1
|
||||||
base_volume_name = var.debian_buster_qcow2
|
base_volume_name = local.debian_buster_qcow2
|
||||||
count = var.number_domain
|
count = var.number_domain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user