From b444fd7327aa93ca3309a1388979d222e546df5f Mon Sep 17 00:00:00 2001 From: Marshall McDonnell <mcdonnellmt@ornl.gov> Date: Tue, 19 Jan 2021 14:17:28 -0500 Subject: [PATCH 1/2] Rename module + add apt support to template --- .../haproxy-install.sh.tpl | 17 ++++++++++++++++- .../inputs.tf | 2 +- .../main.tf | 0 .../outputs.tf | 0 4 files changed, 17 insertions(+), 2 deletions(-) rename modules/{cades-load-balancer-haproxy => ornl-cloud-load-balancer-haproxy}/haproxy-install.sh.tpl (87%) rename modules/{cades-load-balancer-haproxy => ornl-cloud-load-balancer-haproxy}/inputs.tf (93%) rename modules/{cades-load-balancer-haproxy => ornl-cloud-load-balancer-haproxy}/main.tf (100%) rename modules/{cades-load-balancer-haproxy => ornl-cloud-load-balancer-haproxy}/outputs.tf (100%) diff --git a/modules/cades-load-balancer-haproxy/haproxy-install.sh.tpl b/modules/ornl-cloud-load-balancer-haproxy/haproxy-install.sh.tpl similarity index 87% rename from modules/cades-load-balancer-haproxy/haproxy-install.sh.tpl rename to modules/ornl-cloud-load-balancer-haproxy/haproxy-install.sh.tpl index 36f5bfb..5b0d1f8 100644 --- a/modules/cades-load-balancer-haproxy/haproxy-install.sh.tpl +++ b/modules/ornl-cloud-load-balancer-haproxy/haproxy-install.sh.tpl @@ -3,8 +3,23 @@ CONFIG="/etc/haproxy/haproxy.cfg" -sudo dnf install haproxy -y +# Detect package management system. +DNF=$(which dnf 2>/dev/null) +APT_GET=$(which apt-get 2>/dev/null) +if [[ ! -z $DNF ]]; then + echo "RHEL/CentOS system detected" + echo "Installing HAProxy" + sudo dnf install haproxy -y +elif [[ ! -z $APT_GET ]]; then + echo "Debian/Ubuntu system detected" + echo "Installing HAProxy" + sudo apt install haproxy -y +else + echo "Prerequisites not installed due to OS detection failure" + exit 1; +fi +# Add HAProxy files sudo mkdir -p /etc/haproxy echo " diff --git a/modules/cades-load-balancer-haproxy/inputs.tf b/modules/ornl-cloud-load-balancer-haproxy/inputs.tf similarity index 93% rename from modules/cades-load-balancer-haproxy/inputs.tf rename to modules/ornl-cloud-load-balancer-haproxy/inputs.tf index 8e9cbd3..446a92c 100644 --- a/modules/cades-load-balancer-haproxy/inputs.tf +++ b/modules/ornl-cloud-load-balancer-haproxy/inputs.tf @@ -36,7 +36,7 @@ variable "security_groups" { } variable "image" { - default = "CADES_CentOS-8.1_AppStream_v20200414_1" + default = "CADES_Ubuntu-20.04_v20200428_1" } variable "flavor" { diff --git a/modules/cades-load-balancer-haproxy/main.tf b/modules/ornl-cloud-load-balancer-haproxy/main.tf similarity index 100% rename from modules/cades-load-balancer-haproxy/main.tf rename to modules/ornl-cloud-load-balancer-haproxy/main.tf diff --git a/modules/cades-load-balancer-haproxy/outputs.tf b/modules/ornl-cloud-load-balancer-haproxy/outputs.tf similarity index 100% rename from modules/cades-load-balancer-haproxy/outputs.tf rename to modules/ornl-cloud-load-balancer-haproxy/outputs.tf -- GitLab From c4f40e2e56d22a3175a3dbe70bc53ff22ed25225 Mon Sep 17 00:00:00 2001 From: Marshall McDonnell <mcdonnellmt@ornl.gov> Date: Tue, 19 Jan 2021 14:17:40 -0500 Subject: [PATCH 2/2] Update examples and server template --- examples/server-install.sh.tpl | 20 ++++++++++++++++++-- examples/two_servers_one_port/main.tf | 12 ++++++------ examples/two_servers_two_ports/main.tf | 12 ++++++------ examples/two_servers_two_ports_same/main.tf | 12 ++++++------ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/examples/server-install.sh.tpl b/examples/server-install.sh.tpl index 6f347f3..d74a347 100644 --- a/examples/server-install.sh.tpl +++ b/examples/server-install.sh.tpl @@ -1,6 +1,22 @@ #!/bin/bash -sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo -sudo dnf install docker-ce -y --nobest + +# Detect package management system. +DNF=$(which dnf 2>/dev/null) +APT_GET=$(which apt-get 2>/dev/null) +if [[ ! -z $DNF ]]; then + echo "RHEL/CentOS system detected" + echo "Installing Docker" + sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo + sudo dnf install docker-ce -y --nobest +elif [[ ! -z $APT_GET ]]; then + echo "Debian/Ubuntu system detected" + echo "Installing HAProxy" + sudo apt install docker-ce +else + echo "Prerequisites not installed due to OS detection failure" + exit 1; +fi + sudo systemctl enable --now docker %{ for server_port in server_ports ~} diff --git a/examples/two_servers_one_port/main.tf b/examples/two_servers_one_port/main.tf index 7713901..69217a1 100644 --- a/examples/two_servers_one_port/main.tf +++ b/examples/two_servers_one_port/main.tf @@ -25,7 +25,7 @@ variable "server_port" { resource "openstack_compute_instance_v2" "servers" { name = "lb-haproxy-backend-${count.index}" - image_name = "CADES_CentOS-8.1_AppStream_v20200414_1" + image_name = "CADES_Ubuntu-20.04_v20200428_1" flavor_name = "m1.tiny" security_groups = var.security_groups count = 2 @@ -39,8 +39,8 @@ resource "openstack_compute_instance_v2" "servers" { }) } -module "cades_lb_haproxy" { - source = "git::https://code.ornl.gov/rse-terraform-modules/cades-load-balancer-haproxy//modules/cades-load-balancer-haproxy" +module "ornl_cloud_lb_haproxy" { + source = "git::https://code.ornl.gov/rse-terraform-modules/ornl-cloud-load-balancer-haproxy//modules/ornl-cloud-load-balancer-haproxy" name = "lb-haproxy-loadbalancer" ports = [ @@ -57,13 +57,13 @@ module "cades_lb_haproxy" { } output "lb_ip" { - value = module.cades_lb_haproxy.lb_ip + value = module.ornl_cloud_lb_haproxy.lb_ip } output "server_ip_list" { - value = module.cades_lb_haproxy.server_ip_list + value = module.ornl_cloud_lb_haproxy.server_ip_list } output "ports" { - value = module.cades_lb_haproxy.frontend_ports + value = module.ornl_cloud_lb_haproxy.frontend_ports } diff --git a/examples/two_servers_two_ports/main.tf b/examples/two_servers_two_ports/main.tf index 35ccbd3..a9312f1 100644 --- a/examples/two_servers_two_ports/main.tf +++ b/examples/two_servers_two_ports/main.tf @@ -25,7 +25,7 @@ variable "server_port_B" { resource "openstack_compute_instance_v2" "servers" { name = "lb-haproxy-backend-${count.index}" - image_name = "CADES_CentOS-8.1_AppStream_v20200414_1" + image_name = "CADES_Ubuntu-20.04_v20200428_1" flavor_name = "m1.tiny" security_groups = var.security_groups count = 2 @@ -39,8 +39,8 @@ resource "openstack_compute_instance_v2" "servers" { }) } -module "cades_lb_haproxy" { - source = "git::https://code.ornl.gov/rse-terraform-modules/cades-load-balancer-haproxy//modules/cades-load-balancer-haproxy" +module "ornl_cloud_lb_haproxy" { + source = "git::https://code.ornl.gov/rse-terraform-modules/ornl-cloud-load-balancer-haproxy//modules/ornl-cloud-load-balancer-haproxy" name = "lb-haproxy-loadbalancer" ports = [ @@ -61,13 +61,13 @@ module "cades_lb_haproxy" { } output "lb_ip" { - value = module.cades_lb_haproxy.lb_ip + value = module.ornl_cloud_lb_haproxy.lb_ip } output "server_ip_list" { - value = module.cades_lb_haproxy.server_ip_list + value = module.ornl_cloud_lb_haproxy.server_ip_list } output "ports" { - value = module.cades_lb_haproxy.frontend_ports + value = module.ornl_cloud_lb_haproxy.frontend_ports } diff --git a/examples/two_servers_two_ports_same/main.tf b/examples/two_servers_two_ports_same/main.tf index 4b716cd..64ecbb4 100644 --- a/examples/two_servers_two_ports_same/main.tf +++ b/examples/two_servers_two_ports_same/main.tf @@ -107,8 +107,8 @@ resource "openstack_compute_instance_v2" "servers" { }) } -module "cades_lb_haproxy" { - source = "git::https://code.ornl.gov/rse-terraform-modules/cades-load-balancer-haproxy//modules/cades-load-balancer-haproxy" +module "ornl_cloud_lb_haproxy" { + source = "git::https://code.ornl.gov/rse-terraform-modules/ornl-cloud-load-balancer-haproxy//modules/ornl-cloud-load-balancer-haproxy" name = "lb-haproxy-loadbalancer" ports = [ @@ -129,17 +129,17 @@ module "cades_lb_haproxy" { } output "lb_ip" { - value = module.cades_lb_haproxy.lb_ip + value = module.ornl_cloud_lb_haproxy.lb_ip } output "server_ip_list" { - value = module.cades_lb_haproxy.server_ip_list + value = module.ornl_cloud_lb_haproxy.server_ip_list } output "frontend_ports" { - value = module.cades_lb_haproxy.frontend_ports + value = module.ornl_cloud_lb_haproxy.frontend_ports } output "backend_ports" { - value = module.cades_lb_haproxy.backend_ports + value = module.ornl_cloud_lb_haproxy.backend_ports } -- GitLab