From ffdac4096d15be2cb7448516798e6486c0e7defb Mon Sep 17 00:00:00 2001 From: Cody Hill <15899666+c0dyhi11@users.noreply.github.com> Date: Wed, 25 Nov 2020 20:56:34 -0600 Subject: [PATCH] CentOS 8 Support and Ubuntu 18.04 tested (#20) --- README.md | 7 +- main.tf | 9 +-- output.tf | 2 +- templates/{deploy_cluster.sh => pre_reqs.sh} | 72 +++++++++++++++----- 4 files changed, 68 insertions(+), 22 deletions(-) rename templates/{deploy_cluster.sh => pre_reqs.sh} (52%) diff --git a/README.md b/README.md index 1c70024..0ec255e 100644 --- a/README.md +++ b/README.md @@ -142,10 +142,15 @@ Worker_Public_IPs = [ | Name | Api Slug | | :-----------------------: | :----------: | | CentOS 8 | centos_8 | -| RedHat Enterprise Linux 8 | rhel_8 | | Ubuntu 18.04 | ubuntu_18_04 | | Ubutnu 20.04 | ubuntu_20_04 | +## Operating Systems that need fixing +| Name | Api Slug | +| :-----------------------: | :----------: | +| Red Hat Enterprise Linux 8 | rhel_8 | + + ## Variables | Variable Name | Type | Default Value | Description | diff --git a/main.tf b/main.tf index c16235e..2122921 100644 --- a/main.tf +++ b/main.tf @@ -133,9 +133,10 @@ resource "null_resource" "write_ssh_private_key" { } data "template_file" "deploy_anthos_cluster" { - template = file("templates/deploy_cluster.sh") + template = file("templates/pre_reqs.sh") vars = { - cluster_name = local.cluster_name + cluster_name = local.cluster_name + operating_system = var.operating_system } } @@ -168,7 +169,7 @@ resource "null_resource" "prep_anthos_cluster" { provisioner "file" { content = data.template_file.deploy_anthos_cluster.rendered - destination = "/root/baremetal/deploy_cluster.sh" + destination = "/root/baremetal/pre_reqs.sh" } provisioner "file" { @@ -177,7 +178,7 @@ resource "null_resource" "prep_anthos_cluster" { } provisioner "remote-exec" { - inline = ["bash /root/baremetal/deploy_cluster.sh"] + inline = ["bash /root/baremetal/pre_reqs.sh"] } } diff --git a/output.tf b/output.tf index f33b600..46bf9c1 100644 --- a/output.tf +++ b/output.tf @@ -28,7 +28,7 @@ output "Worker_Node_Tags" { description = "Worker Node Tags" } -output "ssh_key_lcation" { +output "ssh_key_location" { value = local_file.cluster_private_key_pem.filename description = "The SSH Private Key File Location" } diff --git a/templates/deploy_cluster.sh b/templates/pre_reqs.sh similarity index 52% rename from templates/deploy_cluster.sh rename to templates/pre_reqs.sh index 974fd5d..52bf9cd 100644 --- a/templates/deploy_cluster.sh +++ b/templates/pre_reqs.sh @@ -1,18 +1,60 @@ #!/bin/bash -# Install Docker -sudo apt update -y -sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg -y -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" -y -sudo apt update -y -sudo apt install docker-ce -y -sudo usermod -aG docker $USER - -# Install Google Cloud SDK -echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list -curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - -sudo apt-get update -y -sudo apt-get install google-cloud-sdk -y +CLUSTER_NAME='${cluster_name}' +OS='${operating_system}' + +function ubuntu_pre_reqs { + # Install Docker + sudo apt update -y + sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg -y + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" -y + sudo apt update -y + sudo apt install docker-ce -y + sudo usermod -aG docker $USER + + # Install Google Cloud SDK + echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - + sudo apt-get update -y + sudo apt-get install google-cloud-sdk -y +} + + +function rhel_pre_reqs { + # Disable Firewalld + sudo systemctl disable firewalld + sudo systemctl stop firewalld + # Disable SELinux + sudo setenforce 0 + sudo curl -Lo /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo + + sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM +[google-cloud-sdk] +name=Google Cloud SDK +baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64 +enabled=1 +gpgcheck=1 +repo_gpgcheck=1 +gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg + https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg +EOM + + sudo dnf install docker-ce iptables google-cloud-sdk python3 -y + sudo systemctl enable --now docker +} + + +function unknown_os { + echo "I don't konw who I am" > /root/who_am_i.txt +} + +if [ "$${OS:0:6}" = "centos" ] || [ "$${OS:0:4}" = "rhel" ]; then + rhel_pre_reqs +elif [ "$${OS:0:6}" = "ubuntu" ]; then + ubuntu_pre_reqs +else + unknown_os +fi # Install kubectl curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.6/bin/linux/amd64/kubectl" @@ -25,8 +67,6 @@ gcloud auth activate-service-account --key-file=keys/gcr.json gsutil cp gs://anthos-baremetal-release/bmctl/0.7.0-gke.6/linux/bmctl . chmod a+x bmctl -# Generate boilerplate cluster config -CLUSTER_NAME="${cluster_name}" ./bmctl create config -c $CLUSTER_NAME # Replace variables in cluster config