Creates 1 amazn, 1 ubuntu to test ansible.

ansible-test
shnee 4 years ago
parent f357d3dd5b
commit b0b959f28b

@ -1,3 +1,5 @@
vm-name-prefix = "docker-ansible-test"
# A CIDR block ending in '/32' equates to a single IP address, '0.0.0.0/0'
# equates to any ip address.
admin-ips = [ "8.8.8.8/32", "0.0.0.0/0" ]
@ -21,7 +23,11 @@ aws-ec2-instance-type = "t2.micro"
# AWS Amazon Linux 2 AMI (HVM), SSD Volume Type - Oregon - 2021.11.11 - free
# base-image = "ami-00be885d550dcee43"
# AWS Amazon Linux 2 AMI (HVM), SSD Volume Type - us-east-2 - 2021.11.12 - free
base-image = "ami-0dd0ccab7e2801812"
# base-image = "ami-0dd0ccab7e2801812"
# Ubuntu Server 20.04 LTS (HVM), SSD Volume Type
# us-east-2 - (64-bit x86) - 2021.11.12 - free
base-image = "ami-0629230e074c580f2"
# base-image = "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img"
# From https://cloud.centos.org/centos/7/images/ from 2020-11-12 06:52
# base-image = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2009.qcow2"

@ -12,24 +12,44 @@ terraform {
# cloud-init
################################################################################
data "template_file" "master-node-user-datas" {
# data "template_file" "master-node-user-datas" {
# template = file("${path.module}/cloud_init.cfg")
# vars = {
# admin-passwd = "${var.root-admin-passwd}"
# admin-pub-key = "${var.root-admin-pub-key}"
# hostname = "${var.vm-name-prefix}-master-${count.index}"
# }
# count = var.master-nodes
# }
#
# data "template_file" "worker-node-user-datas" {
# template = file("${path.module}/cloud_init.cfg")
# vars = {
# admin-passwd = "${var.root-admin-passwd}"
# admin-pub-key = "${var.root-admin-pub-key}"
# hostname = "${var.vm-name-prefix}-worker-${count.index}"
# }
# count = var.worker-nodes
# }
data "template_file" "amzn2-node-user-datas" {
template = file("${path.module}/cloud_init.cfg")
vars = {
admin-passwd = "${var.root-admin-passwd}"
admin-pub-key = "${var.root-admin-pub-key}"
hostname = "${var.vm-name-prefix}-master-${count.index}"
hostname = "${var.vm-name-prefix}-amzn2-${count.index}"
}
count = var.master-nodes
count = 1
}
data "template_file" "worker-node-user-datas" {
data "template_file" "ubuntu-node-user-datas" {
template = file("${path.module}/cloud_init.cfg")
vars = {
admin-passwd = "${var.root-admin-passwd}"
admin-pub-key = "${var.root-admin-pub-key}"
hostname = "${var.vm-name-prefix}-worker-${count.index}"
hostname = "${var.vm-name-prefix}-ubuntu-${count.index}"
}
count = var.worker-nodes
count = 1
}
################################################################################
@ -60,28 +80,50 @@ resource "aws_key_pair" "key" {
}
}
module "master-nodes" {
module "amzn2-nodes" {
source = "./modules/aws-nodes"
ami = var.base-image
ec2-instance-type = var.aws-ec2-instance-type
subnet-id = module.aws-network.subnet.id
security-group-ids = [module.aws-network.default-security-group.id]
user-datas = data.template_file.master-node-user-datas
num-nodes = var.master-nodes
name-prefix = "${var.vm-name-prefix}-master"
user-datas = data.template_file.amzn2-node-user-datas
num-nodes = 1
name-prefix = "${var.vm-name-prefix}-amzn2"
}
module "worker-nodes" {
module "ubuntu-nodes" {
source = "./modules/aws-nodes"
ami = var.base-image
ec2-instance-type = var.aws-ec2-instance-type
subnet-id = module.aws-network.subnet.id
security-group-ids = [module.aws-network.default-security-group.id]
user-datas = data.template_file.worker-node-user-datas
num-nodes = var.worker-nodes
name-prefix = "${var.vm-name-prefix}-worker"
user-datas = data.template_file.ubuntu-node-user-datas
num-nodes = 1
name-prefix = "${var.vm-name-prefix}-ubuntu"
}
# module "master-nodes" {
# source = "./modules/aws-nodes"
# ami = var.base-image
# ec2-instance-type = var.aws-ec2-instance-type
# subnet-id = module.aws-network.subnet.id
# security-group-ids = [module.aws-network.default-security-group.id]
# user-datas = data.template_file.master-node-user-datas
# num-nodes = var.master-nodes
# name-prefix = "${var.vm-name-prefix}-master"
# }
#
# module "worker-nodes" {
# source = "./modules/aws-nodes"
# ami = var.base-image
# ec2-instance-type = var.aws-ec2-instance-type
# subnet-id = module.aws-network.subnet.id
# security-group-ids = [module.aws-network.default-security-group.id]
# user-datas = data.template_file.worker-node-user-datas
# num-nodes = var.worker-nodes
# name-prefix = "${var.vm-name-prefix}-worker"
# }
################################################################################
# end aws
################################################################################
@ -134,11 +176,19 @@ module "worker-nodes" {
# end libvirt
################################################################################
# TODO REM move to other file?
output "master-ips" {
value = module.master-nodes.ips
output "amzn2-ips" {
value = module.amzn2-nodes.ips
}
output "worker-ips" {
value = module.worker-nodes.ips
output "ubuntu-ips" {
value = module.ubuntu-nodes.ips
}
# TODO REM move to other file?
# output "master-ips" {
# value = module.master-nodes.ips
# }
#
# output "worker-ips" {
# value = module.worker-nodes.ips
# }

Loading…
Cancel
Save