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:
Antoine 2021-01-24 21:49:30 +01:00
parent a75f875026
commit f70970f0e4
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
7 changed files with 52 additions and 27 deletions

View File

@ -14,4 +14,24 @@ get-ip:
@virsh domifaddr --domain db1
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

View File

@ -1,5 +1,5 @@
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 = {
hostname = format("%s-%s", var.hostname, count.index)
}
@ -7,7 +7,7 @@ data "template_file" "user_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 = {
instance_id = count.index
}

View File

@ -9,7 +9,8 @@ resource "libvirt_domain" "domains" {
running = "true"
autostart = "true"
count = var.number_domain
count = var.number_domain
qemu_agent = true
boot_device {
dev = ["hd", "network"]

View File

@ -16,10 +16,6 @@ terraform {
source = "dmacvicar/libvirt"
version = ">= 0.6.3"
}
docker = {
source = "kreuzwerker/docker"
version = "2.11.0"
}
}
backend "etcdv3" {
@ -42,7 +38,7 @@ resource "null_resource" "delay_10s" {
command = "sleep 120"
}
triggers = {
// trigger after last domain created
# trigger after last domain created
"after" = libvirt_domain.domains[var.number_domain - 1].id
}
}
@ -52,3 +48,17 @@ output "ip" {
value = libvirt_domain.domains.*.network_interface
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"
}

View File

@ -1,10 +1,11 @@
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r/network.markdown
resource "libvirt_network" "private_network" {
name = "private"
mode = "nat"
domain = "network.local"
addresses = ["10.17.3.0/24"]
name = "private"
mode = "bridge" # "nat"
bridge = "br0" # only for bridge mode
# domain = "network.local" # only for nat mode
# addresses = [var.ip] # only for nat mode
autostart = true
dhcp {
enabled = true

View File

@ -1,12 +1,12 @@
variable "ip" {
type = string
default = "10.17.3.35/"
default = "10.17.3.35/24"
description = "fixed ip address for compute"
}
variable "number_domain" {
type = string
default = "3"
default = "4"
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"
}
variable "debian_buster_qcow2" {
type = string
default = "debian-10.7.0-with-docker.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"
locals {
debian_buster_qcow2 = "debian-10.7.0-with-docker.qcow2"
centos7_qcow2 = "centos7.qcow2"
}

View File

@ -7,13 +7,13 @@
resource "libvirt_volume" "root_centos" {
name = "my-root-centos"
pool = var.pool_1
base_volume_name = var.centos7_qcow2
base_volume_name = local.centos7_qcow2
}
resource "libvirt_volume" "root_debian" {
name = format("root-debian-%s", count.index)
pool = var.pool_1
base_volume_name = var.debian_buster_qcow2
base_volume_name = local.debian_buster_qcow2
count = var.number_domain
}