diff --git a/CRI_XCBC b/CRI_XCBC index 1d7a787a562130d8b96d1b85d087c4a3ecc34f41..89297776283f025d8b51e4f83dc7ac78f3ada92b 160000 --- a/CRI_XCBC +++ b/CRI_XCBC @@ -1 +1 @@ -Subproject commit 1d7a787a562130d8b96d1b85d087c4a3ecc34f41 +Subproject commit 89297776283f025d8b51e4f83dc7ac78f3ada92b diff --git a/main.tf b/main.tf index 128e223650c2dc8e457d1531cb493ea1a049c435..c95d2c2cd8f849093eb79e9e6b66e942429db731 100644 --- a/main.tf +++ b/main.tf @@ -65,6 +65,7 @@ module "create-ohpc-instance" { key_pair = "${module.import-keypair.keypair_name}" external_network = var.external_network internal_network = var.internal_network + internal_ip = var.ohpc_private_ip floating_ip_ohpc = "${module.floating-ip-address.ohpc_address}" host_prefix = var.host_prefix ohpc_user = var.ohpc_user @@ -81,6 +82,7 @@ module "create-ood-instance" { flavor = var.flavor key_pair = "${module.import-keypair.keypair_name}" internal_network = var.internal_network + internal_ip = var.ood_private_ip external_network = var.external_network floating_ip_ood = "${module.floating-ip-address.ood_address}" host_prefix = var.host_prefix @@ -108,4 +110,40 @@ output "ohpc-ssh_host" { # calls the outputs defined in the ood-instance module output "ood-ssh_host" { value = "${module.create-ood-instance.ssh_host}" -} \ No newline at end of file +} + +# compute node and ood post provision +# use single null_resource for serial provisioner runs to avoid race conditions +# that lead to inconsistent deploy successes. +resource "null_resource" "ops" { + triggers = { + ohpc_instance = module.create-ohpc-instance.id + compute_instances = join(",", module.nodes.id) + } + + connection { + host = module.create-ohpc-instance.ssh_host + user = var.ohpc_user + private_key = file(var.ssh_private_key) + } + + # moves CRI_XCBC file into directory made above + provisioner "file" { + source = "CRI_XCBC" + destination = "/" + } + + # compute node + provisioner "remote-exec" { + inline = [ + for node, net in module.nodes.network: + "ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` -e \"{'compute_nodes':[{'name':'${node}', 'ip':'${net[0].fixed_ip_v4}', 'mac':'${net[0].mac}', 'vnfs':'', 'sockets':'1', 'corespersocket':'1'}]}\" /CRI_XCBC/site-ops.yaml -b -v"] + } + + # ood node + provisioner "remote-exec" { + inline = [ + for net in module.create-ood-instance.network: + "ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` -e \"{'compute_nodes':[{'name':'${var.ood_instance_name}', 'ip':'${net.fixed_ip_v4}', 'mac':'${net.mac}', 'vnfs':'', 'sockets':'1', 'corespersocket':'1'}]}\" /CRI_XCBC/site-ops.yaml -b -v"] + } +} diff --git a/nodes/main.tf b/nodes/main.tf index 5fdb441aacee4bcd7c26596cc5d0be28ce5c2ef6..dfeeeadd5fa32df3107c5e63258e0833506de556 100644 --- a/nodes/main.tf +++ b/nodes/main.tf @@ -10,20 +10,44 @@ variable "key_pair" {type = "string"} variable "compute_node_count" { } variable "internal_network" {} - +data "openstack_images_image_v2" "compute" { + name = var.image_compute + most_recent = true +} # creates compute node -resource "openstack_compute_instance_v2" "c0" { +resource "openstack_compute_instance_v2" "compute" { depends_on = [var.internal_subnet_id] name = "c${count.index}" - image_name = var.image_compute + image_id = data.openstack_images_image_v2.compute.id flavor_name = var.flavor key_pair = var.key_pair security_groups = ["default"] count = var.compute_node_count + user_data = <<-EOF + #cloud-config + runcmd: + - [ bash, -xc, 'ethernet=$(cat /sys/class/net/eth0/address); nodename=$(hostname -s); sed -e "s/MY_HWADDR/$ethernet/" -e "s/MY_NODENAME/$nodename/" -i /warewulf/config;' ] + - [ bash, -xc, "echo $(date) ': hello world!'; until WWGETFILES_INTERVAL=0 bash -x /warewulf/bin/wwgetfiles; do echo waiting ; rm -f /tmp/.wwgetfile.lock ; sleep 10; done;" ] + - [ bash, -xc, "systemctl restart munge" ] + - [ bash, -xc, "systemctl restart slurmd" ] + EOF # defines the networks of the instance network { name = var.internal_network } -} \ No newline at end of file +} + +# output +output "id" { + value = openstack_compute_instance_v2.compute.*.id +} + +output "image_id" { + value = data.openstack_images_image_v2.compute.id +} + +output "network" { + value = zipmap(openstack_compute_instance_v2.compute.*.name, openstack_compute_instance_v2.compute.*.network) +} diff --git a/ohpc-instance/main.tf b/ohpc-instance/main.tf index c41ad802d3b981b170eb7e956d73043d0d2e7817..cf39081368c88a4208823ef9ea0af75dcf87ee35 100644 --- a/ohpc-instance/main.tf +++ b/ohpc-instance/main.tf @@ -9,6 +9,7 @@ variable "flavor" {} variable "key_pair" {type = "string"} variable "internal_network" {} +variable "internal_ip" {} variable "external_network" {} # is created in floating-ip module and called in root module @@ -27,6 +28,15 @@ resource "openstack_compute_instance_v2" "ohpc" { flavor_name = var.flavor key_pair = var.key_pair security_groups = ["default"] + user_data = <<-EOF + #cloud-config + write_files: + - content: | + 10.1.1.10 ohpc ohpc.novalocal + owner: centos:centos + path: /etc/hosts + permissions: 0644 + EOF # defines the networks of the instance network { @@ -34,6 +44,7 @@ resource "openstack_compute_instance_v2" "ohpc" { } network { name = var.internal_network + fixed_ip_v4 = var.internal_ip } } @@ -50,6 +61,10 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { } } +output "id" { + value = openstack_compute_instance_v2.ohpc.id +} + output "ssh_host" { value = format(var.host_prefix,element(split(".", var.floating_ip_ohpc),3,),) -} \ No newline at end of file +} diff --git a/ood-instance/main.tf b/ood-instance/main.tf index 09e8ce5cdb33954e567c588b47de5e34b9dce5d2..a6a4419dd94634936cb51b31187cb4349bf6656f 100644 --- a/ood-instance/main.tf +++ b/ood-instance/main.tf @@ -9,6 +9,7 @@ variable "flavor" {} variable "key_pair" {type = "string"} variable "internal_network" {} +variable "internal_ip" {} variable "external_network" {} # is created in floating-ip module and called in root module @@ -27,6 +28,15 @@ resource "openstack_compute_instance_v2" "ood" { flavor_name = var.flavor key_pair = var.key_pair security_groups = ["default"] + user_data = <<-EOF + #cloud-config + runcmd: + - [ bash, -xc, 'ethernet=$(cat /sys/class/net/eth1/address); nodename=$(hostname -s); sed -e "s/MY_HWADDR/$ethernet/" -e "s/MY_NODENAME/$nodename/" -i /warewulf/config;' ] + - [ bash, -xc, "until WWGETFILES_INTERVAL=0 bash -x /warewulf/bin/wwgetfiles; do echo waiting ; rm -f /tmp/.wwgetfile.lock ; sleep 10; done;" ] + - [ bash, -xc, "systemctl restart munge" ] + - [ bash, -xc, "cd /CRI_XCBC; ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/ood-ops.yaml -b -v" ] + EOF + # defines the networks of the instance network { @@ -34,6 +44,7 @@ resource "openstack_compute_instance_v2" "ood" { } network { name = var.internal_network + fixed_ip_v4 = var.internal_ip } } @@ -51,7 +62,12 @@ resource "openstack_compute_floatingip_associate_v2" "ood" { } - +output "id" { + value = openstack_compute_instance_v2.ood.id +} output "ssh_host"{ value = format(var.host_prefix,element(split(".", var.floating_ip_ood),3,),) -} \ No newline at end of file +} +output "network" { + value = openstack_compute_instance_v2.ood.network +} diff --git a/vars.tf b/vars.tf index b95a6f264ddc1c3fbf8746f8cbf152902294b758..00bbcd100a31a4f8cee76c2d3e64636e339588e9 100644 --- a/vars.tf +++ b/vars.tf @@ -14,9 +14,11 @@ variable "ssh_public_key" {default = "~/.ssh/id_rsa.pub"} # variables for instance modules variable "ohpc_instance_name" {default = "ohpc"} +variable "ohpc_private_ip" {default = "10.1.1.10"} variable "ood_instance_name" { default = "ood"} variable "image_ohpc" {default = "CentOS-7-x86_64-GenericCloud-1905"} variable "image_ood" {default = "CentOS-7-x86_64-GenericCloud-1905"} +variable "ood_private_ip" {default = "10.1.1.11"} variable "flavor" {default = "m1.medium"} variable "internal_network" {default = "clusternet"} variable "external_network" {default = "dmznet"}