From c26fa309c10c4e498c29d535de719a2d313b0ae1 Mon Sep 17 00:00:00 2001 From: Torsten Wendland Date: Wed, 6 Apr 2022 16:26:07 +0200 Subject: [PATCH] Reimplemented and merged code for #220 Reimplemented and merged code for #220 --- docs/var.tfvars-doc.md | 32 +++++++++- modules/1_bastion/bastion.tf | 2 +- modules/3_helpernode/helpernode.tf | 59 +++++++++++++++++- .../templates/helpernode_vars.yaml | 2 +- modules/3_helpernode/variables.tf | 1 + modules/5_install/install.tf | 62 ++++++++++++++++--- ocp.tf | 1 + var.tfvars | 1 + variables.tf | 5 ++ 9 files changed, 150 insertions(+), 15 deletions(-) diff --git a/docs/var.tfvars-doc.md b/docs/var.tfvars-doc.md index fe16fbca8..e4ccc3dca 100644 --- a/docs/var.tfvars-doc.md +++ b/docs/var.tfvars-doc.md @@ -194,14 +194,44 @@ This variable can be used for trying out custom OpenShift install image for deve release_image_override = "" ``` -These variables specify the ansible playbooks that are used for OpenShift install and post-install customizations. +These variables specify the ansible playbooks that are used for OpenShift install and post-install customizations. If the URL ends with a file name extension .zip, then it is assumed that it points to a HTTP/HTTPS server and curl/unzip will be used to extract the package. URLs without ending with .zip are recognized as GitHub repositories and git clone && git checkout are used. +`Only .zip is supported file format on web servers. The all files must be placed in folders starting with ocp4-playbooks, or ocp4-helpernode! It is allowed to extend the directory name with additional informations: e.g. ocp4-helpernode- - 50 for OpenshiftSDN and - 100 for OVNKubernetes network provider. ``` private_network_mtu = 1450 diff --git a/modules/1_bastion/bastion.tf b/modules/1_bastion/bastion.tf index 3afd94fab..65d27563b 100644 --- a/modules/1_bastion/bastion.tf +++ b/modules/1_bastion/bastion.tf @@ -265,7 +265,7 @@ resource "null_resource" "bastion_packages" { provisioner "remote-exec" { inline = [ "#sudo yum update -y --skip-broken", - "sudo yum install -y wget jq git net-tools vim python3 tar" + "sudo yum install -y wget jq git net-tools vim python3 tar curl unzip" ] } provisioner "remote-exec" { diff --git a/modules/3_helpernode/helpernode.tf b/modules/3_helpernode/helpernode.tf index c5bbd51ce..896fcceb9 100644 --- a/modules/3_helpernode/helpernode.tf +++ b/modules/3_helpernode/helpernode.tf @@ -69,6 +69,7 @@ locals { ] local_registry = local.local_registry + helm_repo = var.helm_repo client_tarball = var.openshift_client_tarball install_tarball = var.openshift_install_tarball } @@ -78,12 +79,11 @@ locals { } } -resource "null_resource" "config" { - +resource "null_resource" "prep_helpernode_tools_git" { triggers = { bootstrap_count = var.bootstrap_port_ip == "" ? 0 : 1 - worker_count = length(var.worker_port_ips) } + count = length(regexall("\\.zip$", var.helpernode_repo)) == 0 ? 1 : 0 connection { type = "ssh" @@ -104,6 +104,59 @@ resource "null_resource" "config" { "cd ocp4-helpernode && git checkout ${var.helpernode_tag}" ] } +} + +resource "null_resource" "prep_helpernode_tools_curl" { + triggers = { + bootstrap_count = var.bootstrap_port_ip == "" ? 0 : 1 + } + count = length(regexall("\\.zip$", var.helpernode_repo)) > 0 ? 1 : 0 + + connection { + type = "ssh" + user = var.rhel_username + host = var.bastion_ip[0] + private_key = var.private_key + agent = var.ssh_agent + timeout = "${var.connection_timeout}m" + bastion_host = var.jump_host + } + + provisioner "remote-exec" { + inline = [ + "mkdir -p .openshift", + "rm -rf ocp4-helpernode", + "rm -rf ocp4-extract-helper", + "mkdir -p ocp4-extract-helper", + "echo 'Downloading ocp4-helpernode...'", + "curl -o ocp4-extract-helper/ocp4-helpernode.zip ${var.helpernode_repo}", + "echo 'Extracting ocp4-helpernode...'", + "cd ocp4-extract-helper && unzip ocp4-helpernode.zip", + "cd .. && rm -rf ocp4-extract-helper/ocp4-helpernode.zip", + "mv ocp4-extract-helper/ocp4-helpernode* ocp4-helpernode", + "rm -rf ocp4-extract-helper" + ] + } +} + +resource "null_resource" "config" { + depends_on = [null_resource.prep_helpernode_tools_git, null_resource.prep_helpernode_tools_curl] + + triggers = { + bootstrap_count = var.bootstrap_port_ip == "" ? 0 : 1 + worker_count = length(var.worker_port_ips) + } + + connection { + type = "ssh" + user = var.rhel_username + host = var.bastion_ip[0] + private_key = var.private_key + agent = var.ssh_agent + timeout = "${var.connection_timeout}m" + bastion_host = var.jump_host + } + provisioner "file" { content = templatefile("${path.module}/templates/helpernode_inventory", local.helpernode_inventory) destination = "ocp4-helpernode/inventory" diff --git a/modules/3_helpernode/templates/helpernode_vars.yaml b/modules/3_helpernode/templates/helpernode_vars.yaml index 9cb8a6a7e..c04c40603 100644 --- a/modules/3_helpernode/templates/helpernode_vars.yaml +++ b/modules/3_helpernode/templates/helpernode_vars.yaml @@ -90,4 +90,4 @@ ocp_initramfs: "file:///dev/null" ocp_install_kernel: "file:///dev/null" # This is required for latest helpernode. TODO: Remove when https://github.com/RedHatOfficial/ocp4-helpernode/pull/140 is merged -helm_source: "https://get.helm.sh/helm-v3.4.0-linux-ppc64le.tar.gz" +helm_source: "${helm_repo}" diff --git a/modules/3_helpernode/variables.tf b/modules/3_helpernode/variables.tf index 30d9e747a..9b9661edb 100644 --- a/modules/3_helpernode/variables.tf +++ b/modules/3_helpernode/variables.tf @@ -60,6 +60,7 @@ variable "ocp_release_tag" {} variable "helpernode_repo" {} variable "helpernode_tag" {} +variable "helm_repo" {} variable "ansible_extra_options" {} diff --git a/modules/5_install/install.tf b/modules/5_install/install.tf index b0d7ab984..c8dbc9531 100644 --- a/modules/5_install/install.tf +++ b/modules/5_install/install.tf @@ -84,6 +84,58 @@ locals { } } +resource "null_resource" "prep_playbooks_tools_git" { + count = length(regexall("\\.zip$", var.install_playbook_repo)) == 0 ? 1 : 0 + + connection { + type = "ssh" + user = var.rhel_username + host = var.bastion_ip[0] + private_key = var.private_key + agent = var.ssh_agent + timeout = "${var.connection_timeout}m" + bastion_host = var.jump_host + } + + provisioner "remote-exec" { + inline = [ + "rm -rf ocp4-playbooks", + "echo 'Cloning into ocp4-playbooks...'", + "git clone ${var.install_playbook_repo} --quiet", + "cd ocp4-playbooks && git checkout ${var.install_playbook_tag}" + ] + } +} + +resource "null_resource" "prep_playbooks_tools_curl" { + count = length(regexall("\\.zip$", var.install_playbook_repo)) > 0 ? 1 : 0 + + connection { + type = "ssh" + user = var.rhel_username + host = var.bastion_ip[0] + private_key = var.private_key + agent = var.ssh_agent + timeout = "${var.connection_timeout}m" + bastion_host = var.jump_host + } + + provisioner "remote-exec" { + inline = [ + "rm -rf ocp4-playbooks", + "rm -rf ocp4-extract-helper", + "mkdir -p ocp4-extract-helper", + "echo 'Downloading ocp4-playbooks...'", + "curl -o ocp4-extract-helper/ocp4-playbooks.zip ${var.install_playbook_repo}", + "echo 'Extracting ocp4-playbooks...'", + "cd ocp4-extract-helper && unzip ocp4-playbooks.zip", + "cd .. && rm -rf ocp4-extract-helper/ocp4-playbooks.zip", + "mv ocp4-extract-helper/ocp4-playbooks* ocp4-playbooks", + "rm -rf ocp4-extract-helper" + ] + } +} + resource "null_resource" "pre_install" { count = local.bastion_count @@ -111,7 +163,7 @@ resource "null_resource" "pre_install" { } resource "null_resource" "install" { - depends_on = [null_resource.pre_install] + depends_on = [null_resource.prep_playbooks_tools_git, null_resource.prep_playbooks_tools_curl, null_resource.pre_install] triggers = { worker_count = length(var.worker_ips) @@ -127,14 +179,6 @@ resource "null_resource" "install" { bastion_host = var.jump_host } - provisioner "remote-exec" { - inline = [ - "rm -rf ocp4-playbooks", - "echo 'Cloning into ocp4-playbooks...'", - "git clone ${var.install_playbook_repo} --quiet", - "cd ocp4-playbooks && git checkout ${var.install_playbook_tag}" - ] - } provisioner "file" { content = templatefile("${path.module}/templates/install_inventory", local.install_inventory) destination = "ocp4-playbooks/inventory" diff --git a/ocp.tf b/ocp.tf index 92955e0eb..a12ae4152 100644 --- a/ocp.tf +++ b/ocp.tf @@ -113,6 +113,7 @@ module "helpernode" { ocp_release_tag = var.ocp_release_tag helpernode_repo = var.helpernode_repo helpernode_tag = var.helpernode_tag + helm_repo = var.helm_repo ansible_extra_options = var.ansible_extra_options chrony_config = var.chrony_config chrony_config_servers = var.chrony_config_servers diff --git a/var.tfvars b/var.tfvars index fe449bf8b..fe4a92090 100644 --- a/var.tfvars +++ b/var.tfvars @@ -61,6 +61,7 @@ cluster_id = "" # It will use random generated id with #helpernode_tag = "" #install_playbook_repo = "https://github.com/ocp-power-automation/ocp4-playbooks" #install_playbook_tag = "" +#helm_repo = "https://get.helm.sh/helm-v3.6.3-linux-ppc64le.tar.gz" #installer_log_level = "info" #ansible_extra_options = "-v" diff --git a/variables.tf b/variables.tf index 4e8564bb2..f8fba13a3 100644 --- a/variables.tf +++ b/variables.tf @@ -290,6 +290,11 @@ variable "install_playbook_tag" { default = "284b597b3e88c635e3069b82926aa16812238492" } +variable "helm_repo" { + description = "Set the URL after http_server_repo_main_dir pointing to the Python helm modules" + default = "https://get.helm.sh/helm-v3.6.3-linux-ppc64le.tar.gz" +} + variable "ansible_extra_options" { description = "Extra options string to append to ansible-playbook commands" default = "-v"