From c1b636c0c33eb57738fa46a7ad684648d49409df Mon Sep 17 00:00:00 2001 From: Mitchell Moore Date: Wed, 10 Jul 2019 09:30:13 -0500 Subject: [PATCH 1/6] provision ood, skip ohpc ansible --- main.tf | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 3282705..c9ff6b4 100644 --- a/main.tf +++ b/main.tf @@ -3,7 +3,7 @@ resource "openstack_compute_keypair_v2" "keypair" { public_key = "${file("~/.ssh/id_rsa.pub")}" } -#local variable for ssh connect to ohpc +#local variable for ssh connect to OHPC locals { connection = { host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" @@ -80,9 +80,73 @@ depends_on = ["openstack_networking_subnet_v2.dmzsubnet"] } # associates floating ip with the OHPC instance and run the ansible playbook -resource "openstack_compute_floatingip_associate_v2" "ohpc" { +# resource "openstack_compute_floatingip_associate_v2" "ohpc" { +# floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}" +# instance_id = "${openstack_compute_instance_v2.ohpc.id}" + +# provisioner "remote-exec" { +# connection { +# host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" +# user = "centos" +# private_key = "${file("~/.ssh/id_rsa")}" +# } + +# inline = [ +# "sudo mkdir -p /CRI_XCBC && sudo chown centos: /CRI_XCBC", +# "sudo yum install -y epel-release", +# "sudo yum install -y ansible git vim bash-completion", +# "sudo yum install -y NetworkManager", +# "sudo systemctl restart NetworkManager", +# "sudo nmcli con mod 'Wired connection 1' connection.id 'eth1'" +# ] +# } + +# provisioner "file" { +# source = "CRI_XCBC/" +# destination = "/CRI_XCBC/" +# connection { +# host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" +# #host = "${openstack_networking_floatingip_v2.terraform.address}" +# user = "centos" +# private_key = "${file("~/.ssh/id_rsa")}" +# } +# } + +# provisioner "remote-exec" { +# connection { +# host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" +# #host = "${openstack_networking_floatingip_v2.ohpc.address}" +# user = "centos" +# private_key = "${file("~/.ssh/id_rsa")}" +# } +# inline = [ +# "sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b" +# ] +# } +# } + +# creates details for the ood instance using variables defined in vars.tf +resource "openstack_compute_instance_v2" "ood" { +depends_on = ["openstack_networking_subnet_v2.dmzsubnet"] + name = "ood" + image_name = "${var.image}" + flavor_name = "${var.flavor}" + key_pair = "${openstack_compute_keypair_v2.keypair.name}" + security_groups = ["default"] + +# defines the networks of the instance + network { + name = "dmznet" + } + network { + name = "clusternet" + } +} + +# associates floating ip with the OOD instance and run the ansible playbook +resource "openstack_compute_floatingip_associate_v2" "ood" { floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}" - instance_id = "${openstack_compute_instance_v2.ohpc.id}" + instance_id = "${openstack_compute_instance_v2.ood.id}" provisioner "remote-exec" { connection { @@ -115,7 +179,7 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { provisioner "remote-exec" { connection { host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" - #host = "${openstack_networking_floatingip_v2.ohpc.address}" + #host = "${openstack_networking_floatingip_v2.ood.address}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" } @@ -124,3 +188,4 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { ] } } + -- GitLab From 416f414f7fbcea12d8196cd5122439b08d897e45 Mon Sep 17 00:00:00 2001 From: Mitchell Moore Date: Wed, 10 Jul 2019 10:16:39 -0500 Subject: [PATCH 2/6] include ohpc and ood provision --- main.tf | 88 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/main.tf b/main.tf index c9ff6b4..2dfbaa7 100644 --- a/main.tf +++ b/main.tf @@ -80,50 +80,50 @@ depends_on = ["openstack_networking_subnet_v2.dmzsubnet"] } # associates floating ip with the OHPC instance and run the ansible playbook -# resource "openstack_compute_floatingip_associate_v2" "ohpc" { -# floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}" -# instance_id = "${openstack_compute_instance_v2.ohpc.id}" - -# provisioner "remote-exec" { -# connection { -# host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" -# user = "centos" -# private_key = "${file("~/.ssh/id_rsa")}" -# } - -# inline = [ -# "sudo mkdir -p /CRI_XCBC && sudo chown centos: /CRI_XCBC", -# "sudo yum install -y epel-release", -# "sudo yum install -y ansible git vim bash-completion", -# "sudo yum install -y NetworkManager", -# "sudo systemctl restart NetworkManager", -# "sudo nmcli con mod 'Wired connection 1' connection.id 'eth1'" -# ] -# } - -# provisioner "file" { -# source = "CRI_XCBC/" -# destination = "/CRI_XCBC/" -# connection { -# host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" -# #host = "${openstack_networking_floatingip_v2.terraform.address}" -# user = "centos" -# private_key = "${file("~/.ssh/id_rsa")}" -# } -# } - -# provisioner "remote-exec" { -# connection { -# host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" -# #host = "${openstack_networking_floatingip_v2.ohpc.address}" -# user = "centos" -# private_key = "${file("~/.ssh/id_rsa")}" -# } -# inline = [ -# "sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b" -# ] -# } -# } +resource "openstack_compute_floatingip_associate_v2" "ohpc" { + floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}" + instance_id = "${openstack_compute_instance_v2.ohpc.id}" + + provisioner "remote-exec" { + connection { + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + user = "centos" + private_key = "${file("~/.ssh/id_rsa")}" + } + + inline = [ + "sudo mkdir -p /CRI_XCBC && sudo chown centos: /CRI_XCBC", + "sudo yum install -y epel-release", + "sudo yum install -y ansible git vim bash-completion", + "sudo yum install -y NetworkManager", + "sudo systemctl restart NetworkManager", + "sudo nmcli con mod 'Wired connection 1' connection.id 'eth1'" + ] + } + + provisioner "file" { + source = "CRI_XCBC/" + destination = "/CRI_XCBC/" + connection { + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + #host = "${openstack_networking_floatingip_v2.terraform.address}" + user = "centos" + private_key = "${file("~/.ssh/id_rsa")}" + } + } + + provisioner "remote-exec" { + connection { + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + #host = "${openstack_networking_floatingip_v2.ohpc.address}" + user = "centos" + private_key = "${file("~/.ssh/id_rsa")}" + } + inline = [ + "sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b" + ] + } +} # creates details for the ood instance using variables defined in vars.tf resource "openstack_compute_instance_v2" "ood" { -- GitLab From 077abae75f760d7f0b328fdc25eeff1e322f7542 Mon Sep 17 00:00:00 2001 From: Mitchell Moore Date: Wed, 10 Jul 2019 10:59:40 -0500 Subject: [PATCH 3/6] create extra floating ip and refactor variable names --- main.tf | 24 ++++++++++++++---------- output.tf | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/main.tf b/main.tf index 2dfbaa7..c91e50f 100644 --- a/main.tf +++ b/main.tf @@ -6,7 +6,7 @@ resource "openstack_compute_keypair_v2" "keypair" { #local variable for ssh connect to OHPC locals { connection = { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ohpc_ip.address),3))}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" } @@ -57,7 +57,11 @@ resource "openstack_networking_subnet_v2" "clustersubnet" { # defines where floating ip will come from using variable from vars.tf -resource "openstack_networking_floatingip_v2" "ip_pool" { +resource "openstack_networking_floatingip_v2" "ohpc_ip" { + pool = "${var.public-network-name}" +} + +resource "openstack_networking_floatingip_v2" "ood_ip" { pool = "${var.public-network-name}" } @@ -81,12 +85,12 @@ depends_on = ["openstack_networking_subnet_v2.dmzsubnet"] # associates floating ip with the OHPC instance and run the ansible playbook resource "openstack_compute_floatingip_associate_v2" "ohpc" { - floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}" + floating_ip = "${openstack_networking_floatingip_v2.ohpc_ip.address}" instance_id = "${openstack_compute_instance_v2.ohpc.id}" provisioner "remote-exec" { connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ohpc_ip.address),3))}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" } @@ -105,7 +109,7 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { source = "CRI_XCBC/" destination = "/CRI_XCBC/" connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ohpc_ip.address),3))}" #host = "${openstack_networking_floatingip_v2.terraform.address}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" @@ -114,7 +118,7 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { provisioner "remote-exec" { connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ohpc_ip.address),3))}" #host = "${openstack_networking_floatingip_v2.ohpc.address}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" @@ -145,12 +149,12 @@ depends_on = ["openstack_networking_subnet_v2.dmzsubnet"] # associates floating ip with the OOD instance and run the ansible playbook resource "openstack_compute_floatingip_associate_v2" "ood" { - floating_ip = "${openstack_networking_floatingip_v2.ip_pool.address}" + floating_ip = "${openstack_networking_floatingip_v2.ood_ip.address}" instance_id = "${openstack_compute_instance_v2.ood.id}" provisioner "remote-exec" { connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" } @@ -169,7 +173,7 @@ resource "openstack_compute_floatingip_associate_v2" "ood" { source = "CRI_XCBC/" destination = "/CRI_XCBC/" connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" #host = "${openstack_networking_floatingip_v2.terraform.address}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" @@ -178,7 +182,7 @@ resource "openstack_compute_floatingip_associate_v2" "ood" { provisioner "remote-exec" { connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" #host = "${openstack_networking_floatingip_v2.ood.address}" user = "centos" private_key = "${file("~/.ssh/id_rsa")}" diff --git a/output.tf b/output.tf index cac1060..e4646f7 100644 --- a/output.tf +++ b/output.tf @@ -1,5 +1,5 @@ output "address" { - value = "${openstack_networking_floatingip_v2.ip_pool.address}" + value = "${openstack_networking_floatingip_v2.ohpc_ip.address}" } output "dmznet_network_id" { -- GitLab From 32a1edcd6e437627e1f9128b485198f136386221 Mon Sep 17 00:00:00 2001 From: Mitchell Moore Date: Wed, 10 Jul 2019 11:43:00 -0500 Subject: [PATCH 4/6] added ip address output for ood --- output.tf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/output.tf b/output.tf index e4646f7..677d6bd 100644 --- a/output.tf +++ b/output.tf @@ -1,7 +1,11 @@ -output "address" { +output "ohpc_address" { value = "${openstack_networking_floatingip_v2.ohpc_ip.address}" } +output "ood_address" { + value = "${openstack_networking_floatingip_v2.ood_ip.address}" +} + output "dmznet_network_id" { value = "${openstack_networking_network_v2.dmznet.id}" } -- GitLab From 74eb5e880a5314f23382dc8aadedbd34e2a8cae5 Mon Sep 17 00:00:00 2001 From: Mitchell Moore Date: Thu, 11 Jul 2019 14:13:03 -0500 Subject: [PATCH 5/6] fix variable assignments --- main.tf | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/main.tf b/main.tf index 0772663..c97b352 100644 --- a/main.tf +++ b/main.tf @@ -112,36 +112,20 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { } } -# creates details for the ood instance using variables defined in vars.tf -resource "openstack_compute_instance_v2" "ood" { -depends_on = ["openstack_networking_subnet_v2.dmzsubnet"] - name = "ood" - image_name = "${var.image}" - flavor_name = "${var.flavor}" - key_pair = "${openstack_compute_keypair_v2.keypair.name}" - security_groups = ["default"] - -# defines the networks of the instance - network { - name = "dmznet" - } - network { - name = "clusternet" - } -} - # associates floating ip with the OOD instance and run the ansible playbook resource "openstack_compute_floatingip_associate_v2" "ood" { floating_ip = "${openstack_networking_floatingip_v2.ood_ip.address}" instance_id = "${openstack_compute_instance_v2.ood.id}" - - provisioner "remote-exec" { + + # defines ssh connection connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" - user = "centos" - private_key = "${file("~/.ssh/id_rsa")}" + host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + user = "${var.ood-user}" + private_key = "${file(var.ssh-private-key)}" } - + + # installs programs + provisioner "remote-exec" { inline = [ "sudo mkdir -p /CRI_XCBC && sudo chown centos: /CRI_XCBC", "sudo yum install -y epel-release", @@ -152,24 +136,14 @@ resource "openstack_compute_floatingip_associate_v2" "ood" { ] } + # moves CRI_XCBC file into directory made above provisioner "file" { source = "CRI_XCBC/" destination = "/CRI_XCBC/" - connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" - #host = "${openstack_networking_floatingip_v2.terraform.address}" - user = "centos" - private_key = "${file("~/.ssh/id_rsa")}" - } } - + + # runs ansible playbook provisioner "remote-exec" { - connection { - host = "${format("164.111.161.%s", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" - #host = "${openstack_networking_floatingip_v2.ood.address}" - user = "centos" - private_key = "${file("~/.ssh/id_rsa")}" - } inline = [ "sudo ansible-playbook -c local -i /CRI_XCBC/hosts -l `hostname -s` /CRI_XCBC/site.yaml -b" ] -- GitLab From 8e25591acd81706c6f35da04c50923e826d364bc Mon Sep 17 00:00:00 2001 From: Mitchell Moore Date: Thu, 11 Jul 2019 14:32:41 -0500 Subject: [PATCH 6/6] Add ood instance vars and correct ip_pool to ood_ip --- main.tf | 22 ++++++++++++++++++++-- vars.tf | 8 ++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index c97b352..15a2f2a 100644 --- a/main.tf +++ b/main.tf @@ -81,7 +81,7 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { # defines ssh connection connection { - host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ohpc_ip.address),3))}" user = "${var.ohpc-user}" private_key = "${file(var.ssh-private-key)}" } @@ -112,6 +112,24 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" { } } +# creates details for the OOD instance using variables defined in vars.tf +resource "openstack_compute_instance_v2" "ood" { +depends_on = ["openstack_networking_subnet_v2.external_subnet"] + name = "${var.ood-instance-name}" + image_name = "${var.image}" + flavor_name = "${var.flavor}" + key_pair = "${openstack_compute_keypair_v2.keypair.name}" + security_groups = ["default"] + +# defines the networks of the instance + network { + name = "${var.external-net}" + } + network { + name = "${var.internal-net}" + } +} + # associates floating ip with the OOD instance and run the ansible playbook resource "openstack_compute_floatingip_associate_v2" "ood" { floating_ip = "${openstack_networking_floatingip_v2.ood_ip.address}" @@ -119,7 +137,7 @@ resource "openstack_compute_floatingip_associate_v2" "ood" { # defines ssh connection connection { - host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ip_pool.address),3))}" + host = "${format("${var.host-prefix}", element(split(".", openstack_networking_floatingip_v2.ood_ip.address),3))}" user = "${var.ood-user}" private_key = "${file(var.ssh-private-key)}" } diff --git a/vars.tf b/vars.tf index c30b008..376a930 100644 --- a/vars.tf +++ b/vars.tf @@ -49,6 +49,14 @@ variable "ohpc-user" { default = "centos" } +variable "ood-instance-name" { + default = "ood" +} + +variable "ood-user" { + default = "centos" +} + variable "public-network-name" { default = "bright-external-flat-externalnet" } -- GitLab