From 74d6720edc51449aa9add70e233b4fd3fe663e8b Mon Sep 17 00:00:00 2001 From: Torsten Wendland Date: Thu, 8 Jul 2021 15:18:26 +0200 Subject: [PATCH 1/2] Fixes #220 Fixes #220 Implementation how I did it at another customer. I have tested it again on our local test env and both (git and curl) was working like it should be. --- docs/var.tfvars-doc.md | 30 +++++++++- modules/3_helpernode/helpernode.tf | 57 +++++++++++++++++-- .../templates/helpernode_vars.yaml | 2 +- modules/3_helpernode/variables.tf | 1 + modules/5_install/install.tf | 52 ++++++++++++++++- ocp.tf | 1 + var.tfvars | 5 +- variables.tf | 9 ++- 8 files changed, 143 insertions(+), 14 deletions(-) diff --git a/docs/var.tfvars-doc.md b/docs/var.tfvars-doc.md index b680b97c0a..68a7066f49 100644 --- a/docs/var.tfvars-doc.md +++ b/docs/var.tfvars-doc.md @@ -179,12 +179,36 @@ 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 starts with the tag `git:`, then it is assumed that it points to a GitHub server and git clone and git checkout will be used. URLs without this tag and starting with http:/https: will be interpreted as standard web servers and curl will be used to download the packages. +`Only .tar.gz, or .tgz are supported formats on web servers and must be contain a complete git clone of the corresponding project!` +Valid options: Requires a URL pointing to the packages/GitHub project. ``` -helpernode_repo = "https://github.com/RedHatOfficial/ocp4-helpernode" +helpernode_repo = "https:///ocp4-ansible-modules/ocp4-helpernode-latest.tar.gz" +OR +helpernode_repo = "git:https://github.com/RedHatOfficial/ocp4-helpernode" helpernode_tag = "5eab3db53976bb16be582f2edc2de02f7510050d" -install_playbook_repo = "https://github.com/ocp-power-automation/ocp4-playbooks" + +install_playbook_repo = "https:///ocp4-ansible-modules/ocp4-playbooks-latest.tar.gz" +OR +install_playbook_repo = "git:https://github.com/ocp-power-automation/ocp4-playbooks" install_playbook_tag = "02a598faa332aa2c3d53e8edd0e840440ff74bd5" +helm_repo = "https:///python-modules/helm-latest-linux-ppc64le.tar.gz" +``` + +If you want to provide the ansible playbooks by your local HTTP server, follow these steps to clone both git repositories: +``` +git clone https://github.com/RedHatOfficial/ocp4-helpernode +tar czvf ocp4-helpernode.tgz ocp4-helpernode +cp ocp4-helpernode.tgz /var/www/html/repos/ + +git clone https://github.com/ocp-power-automation/ocp4-playbooks +tar czvf ocp4-playbooks.tgz ocp4-playbooks +cp ocp4-playbooks.tgz /var/www/html/repos/ + +ls -la /var/www/html/repos/ +total 13452 +-rw-r--r--. 1 root root 13624204 Jul 8 13:43 ocp4-helpernode.tgz +-rw-r--r--. 1 root root 145165 Jul 8 13:44 ocp4-playbooks.tgz ``` These variables can be used when debugging ansible playbooks diff --git a/modules/3_helpernode/helpernode.tf b/modules/3_helpernode/helpernode.tf index ebe46693de..c62d155190 100644 --- a/modules/3_helpernode/helpernode.tf +++ b/modules/3_helpernode/helpernode.tf @@ -67,6 +67,7 @@ locals { ] local_registry = local.local_registry + helm_repo = var.helm_repo client_tarball = var.openshift_client_tarball install_tarball = var.openshift_install_tarball } @@ -75,12 +76,12 @@ 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("^git:", var.helpernode_repo)) > 0 ? 1 : 0 connection { type = "ssh" @@ -94,13 +95,61 @@ resource "null_resource" "config" { provisioner "remote-exec" { inline = [ - "mkdir -p .openshift", "rm -rf ocp4-helpernode", "echo 'Cloning into ocp4-helpernode...'", - "git clone ${var.helpernode_repo} --quiet", + "git clone ${replace(var.helpernode_repo, "/^git:/", "")} --quiet", "cd ocp4-helpernode && git checkout ${var.helpernode_tag}" ] } +} + +resource "null_resource" "prep_helpernode_tools_curl" { + triggers = { + bootstrap_count = var.bootstrap_port_ip == "" ? 0 : 1 + worker_count = length(var.worker_port_ips) + } + count = length(regexall("^http:|^https:", 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 = [ + "rm -rf ocp4-helpernode", + "echo 'Downloading ocp4-helpernode...'", + "curl -o ocp4-helpernode.tar.gz ${var.helpernode_repo}", + "echo 'Extracting ocp4-helpernode...'", + "tar zxvf ocp4-helpernode.tar.gz", + "rm ocp4-helpernode.tar.gz", + "cd ocp4-helpernode && git checkout ${var.helpernode_tag}" + ] + } +} + +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 = "$HOME/ocp4-helpernode/inventory" diff --git a/modules/3_helpernode/templates/helpernode_vars.yaml b/modules/3_helpernode/templates/helpernode_vars.yaml index 5f3edc414c..2908dc3572 100644 --- a/modules/3_helpernode/templates/helpernode_vars.yaml +++ b/modules/3_helpernode/templates/helpernode_vars.yaml @@ -84,4 +84,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 e17d6f869a..138098e966 100644 --- a/modules/3_helpernode/variables.tf +++ b/modules/3_helpernode/variables.tf @@ -58,6 +58,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 fce5343704..f57f560bf2 100644 --- a/modules/5_install/install.tf +++ b/modules/5_install/install.tf @@ -73,10 +73,11 @@ locals { } } -resource "null_resource" "install" { +resource "null_resource" "prep_playbooks_tools_git" { triggers = { worker_count = length(var.worker_ips) } + count = length(regexall("^git:", var.install_playbook_repo)) > 0 ? 1 : 0 connection { type = "ssh" @@ -92,10 +93,57 @@ resource "null_resource" "install" { inline = [ "rm -rf ocp4-playbooks", "echo 'Cloning into ocp4-playbooks...'", - "git clone ${var.install_playbook_repo} --quiet", + "git clone ${replace(var.install_playbook_repo, "/^git:/", "")} --quiet", + "cd ocp4-playbooks && git checkout ${var.install_playbook_tag}" + ] + } +} + +resource "null_resource" "prep_playbooks_tools_curl" { + triggers = { + worker_count = length(var.worker_ips) + } + count = length(regexall("^http:|^https:", 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 'Downloading ocp4-playbooks...'", + "curl -o ocp4-playbooks.tar.gz ${var.install_playbook_repo}", + "echo 'Extracting ocp4-playbooks...'", + "tar zxvf ocp4-playbooks.tar.gz", + "rm ocp4-playbooks.tar.gz", "cd ocp4-playbooks && git checkout ${var.install_playbook_tag}" ] } +} + +resource "null_resource" "install" { + depends_on = [null_resource.prep_playbooks_tools_git, null_resource.prep_playbooks_tools_curl] + triggers = { + worker_count = length(var.worker_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/install_inventory", local.install_inventory) destination = "$HOME/ocp4-playbooks/inventory" diff --git a/ocp.tf b/ocp.tf index 54d447c7d4..6b9f0545d0 100644 --- a/ocp.tf +++ b/ocp.tf @@ -111,6 +111,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 ccdc5bddf7..6985e275df 100644 --- a/var.tfvars +++ b/var.tfvars @@ -57,10 +57,11 @@ cluster_id = "" # It will use random generated id with #release_image_override = "" -#helpernode_repo = "https://github.com/RedHatOfficial/ocp4-helpernode" +#helpernode_repo = "git:https://github.com/RedHatOfficial/ocp4-helpernode" #helpernode_tag = "" -#install_playbook_repo = "https://github.com/ocp-power-automation/ocp4-playbooks" +#install_playbook_repo = "git:https://github.com/ocp-power-automation/ocp4-playbooks" #install_playbook_tag = "" +#helm_repo = "https://get.helm.sh/helm-v3.4.0-linux-ppc64le.tar.gz" #installer_log_level = "info" #ansible_extra_options = "-v" diff --git a/variables.tf b/variables.tf index b878c92a10..f86fd7e802 100644 --- a/variables.tf +++ b/variables.tf @@ -257,7 +257,7 @@ variable "installer_log_level" { variable "helpernode_repo" { description = "Set the repo URL for using ocp4-helpernode" # Repo for running ocp4 helpernode setup steps. - default = "https://github.com/RedHatOfficial/ocp4-helpernode" + default = "git:https://github.com/RedHatOfficial/ocp4-helpernode" } variable "helpernode_tag" { @@ -269,7 +269,7 @@ variable "helpernode_tag" { variable "install_playbook_repo" { description = "Set the repo URL for using ocp4-playbooks" # Repo for running ocp4 installations steps. - default = "https://github.com/ocp-power-automation/ocp4-playbooks" + default = "git:https://github.com/ocp-power-automation/ocp4-playbooks" } variable "install_playbook_tag" { @@ -278,6 +278,11 @@ variable "install_playbook_tag" { default = "10fec74c9e987b39f7af1127abe304a9e41f8e65" } +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.4.0-linux-ppc64le.tar.gz" +} + variable "ansible_extra_options" { description = "Extra options string to append to ansible-playbook commands" default = "-v" From 59855947f6ee3f0176a4df6fc584e7034d622138 Mon Sep 17 00:00:00 2001 From: Torsten Wendland Date: Fri, 23 Jul 2021 13:07:27 +0200 Subject: [PATCH 2/2] Fixes #220 - Swapped to ZIP Fixes #220 - Swapped to ZIP --- docs/var.tfvars-doc.md | 32 ++++++++++++++++-------------- modules/1_bastion/bastion.tf | 2 +- modules/3_helpernode/helpernode.tf | 14 ++++++------- modules/5_install/install.tf | 14 ++++++------- var.tfvars | 4 ++-- variables.tf | 4 ++-- 6 files changed, 36 insertions(+), 34 deletions(-) diff --git a/docs/var.tfvars-doc.md b/docs/var.tfvars-doc.md index 68a7066f49..60fe9d3fdf 100644 --- a/docs/var.tfvars-doc.md +++ b/docs/var.tfvars-doc.md @@ -179,36 +179,38 @@ 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. If the URL starts with the tag `git:`, then it is assumed that it points to a GitHub server and git clone and git checkout will be used. URLs without this tag and starting with http:/https: will be interpreted as standard web servers and curl will be used to download the packages. -`Only .tar.gz, or .tgz are supported formats on web servers and must be contain a complete git clone of the corresponding project!` +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 a subfolder called ocp4-playbooks-master, or ocp4-helpernode-master! This is the default structure, if you download the playbooks from GitHub.com website and uses the "Download as ZIP" function, which is the recommended way. Exception is the help_repo, which is expected to be a tar.gz file format (default when downloading from the original source without manipulation afterwards!` Valid options: Requires a URL pointing to the packages/GitHub project. ``` -helpernode_repo = "https:///ocp4-ansible-modules/ocp4-helpernode-latest.tar.gz" +helpernode_repo = "https:///ocp4-ansible-modules/ocp4-helpernode-master.zip" OR -helpernode_repo = "git:https://github.com/RedHatOfficial/ocp4-helpernode" +helpernode_repo = "https://github.com/RedHatOfficial/ocp4-helpernode" helpernode_tag = "5eab3db53976bb16be582f2edc2de02f7510050d" -install_playbook_repo = "https:///ocp4-ansible-modules/ocp4-playbooks-latest.tar.gz" +install_playbook_repo = "https:///ocp4-ansible-modules/ocp4-playbooks-master.zip" OR -install_playbook_repo = "git:https://github.com/ocp-power-automation/ocp4-playbooks" +install_playbook_repo = "https://github.com/ocp-power-automation/ocp4-playbooks" install_playbook_tag = "02a598faa332aa2c3d53e8edd0e840440ff74bd5" helm_repo = "https:///python-modules/helm-latest-linux-ppc64le.tar.gz" ``` -If you want to provide the ansible playbooks by your local HTTP server, follow these steps to clone both git repositories: +If you want to provide the ansible playbooks by your local HTTP server, follow these steps: ``` -git clone https://github.com/RedHatOfficial/ocp4-helpernode -tar czvf ocp4-helpernode.tgz ocp4-helpernode -cp ocp4-helpernode.tgz /var/www/html/repos/ +Use your web browser and visit https://github.com/RedHatOfficial/ocp4-helpernode +On the main page of the master brach, click on the green "Code" button with a download symbol in front of it +Click on "Download ZIP" +Upload the file to your local HTTP server and place it in the appropriate directory -git clone https://github.com/ocp-power-automation/ocp4-playbooks -tar czvf ocp4-playbooks.tgz ocp4-playbooks -cp ocp4-playbooks.tgz /var/www/html/repos/ +Use your web browser and visit https://github.com/ocp-power-automation/ocp4-playbooks +On the main page of the master brach, click on the green "Code" button with a download symbol in front of it +Click on "Download ZIP" +Upload the file to your local HTTP server and place it in the appropriate directory ls -la /var/www/html/repos/ total 13452 --rw-r--r--. 1 root root 13624204 Jul 8 13:43 ocp4-helpernode.tgz --rw-r--r--. 1 root root 145165 Jul 8 13:44 ocp4-playbooks.tgz +-rw-r--r--. 1 root root 13624204 Jul 8 13:43 ocp4-helpernode-master.tgz +-rw-r--r--. 1 root root 145165 Jul 8 13:44 ocp4-playbooks-master.tgz ``` These variables can be used when debugging ansible playbooks diff --git a/modules/1_bastion/bastion.tf b/modules/1_bastion/bastion.tf index 9d0a3a28d5..71ca45e1c3 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 c62d155190..bc799f74a9 100644 --- a/modules/3_helpernode/helpernode.tf +++ b/modules/3_helpernode/helpernode.tf @@ -81,7 +81,7 @@ resource "null_resource" "prep_helpernode_tools_git" { bootstrap_count = var.bootstrap_port_ip == "" ? 0 : 1 worker_count = length(var.worker_port_ips) } - count = length(regexall("^git:", var.helpernode_repo)) > 0 ? 1 : 0 + count = length(regexall("\\.zip$", var.helpernode_repo)) == 0 ? 1 : 0 connection { type = "ssh" @@ -97,7 +97,7 @@ resource "null_resource" "prep_helpernode_tools_git" { inline = [ "rm -rf ocp4-helpernode", "echo 'Cloning into ocp4-helpernode...'", - "git clone ${replace(var.helpernode_repo, "/^git:/", "")} --quiet", + "git clone ${var.helpernode_repo} --quiet", "cd ocp4-helpernode && git checkout ${var.helpernode_tag}" ] } @@ -108,7 +108,7 @@ resource "null_resource" "prep_helpernode_tools_curl" { bootstrap_count = var.bootstrap_port_ip == "" ? 0 : 1 worker_count = length(var.worker_port_ips) } - count = length(regexall("^http:|^https:", var.helpernode_repo)) > 0 ? 1 : 0 + count = length(regexall("\\.zip$", var.helpernode_repo)) > 0 ? 1 : 0 connection { type = "ssh" @@ -124,11 +124,11 @@ resource "null_resource" "prep_helpernode_tools_curl" { inline = [ "rm -rf ocp4-helpernode", "echo 'Downloading ocp4-helpernode...'", - "curl -o ocp4-helpernode.tar.gz ${var.helpernode_repo}", + "curl -o ocp4-helpernode.zip ${var.helpernode_repo}", "echo 'Extracting ocp4-helpernode...'", - "tar zxvf ocp4-helpernode.tar.gz", - "rm ocp4-helpernode.tar.gz", - "cd ocp4-helpernode && git checkout ${var.helpernode_tag}" + "unzip ocp4-helpernode.zip", + "mv ocp4-helpernode-master ocp4-helpernode", + "rm ocp4-helpernode.zip" ] } } diff --git a/modules/5_install/install.tf b/modules/5_install/install.tf index f57f560bf2..f549a91081 100644 --- a/modules/5_install/install.tf +++ b/modules/5_install/install.tf @@ -77,7 +77,7 @@ resource "null_resource" "prep_playbooks_tools_git" { triggers = { worker_count = length(var.worker_ips) } - count = length(regexall("^git:", var.install_playbook_repo)) > 0 ? 1 : 0 + count = length(regexall("\\.zip$", var.install_playbook_repo)) == 0 ? 1 : 0 connection { type = "ssh" @@ -93,7 +93,7 @@ resource "null_resource" "prep_playbooks_tools_git" { inline = [ "rm -rf ocp4-playbooks", "echo 'Cloning into ocp4-playbooks...'", - "git clone ${replace(var.install_playbook_repo, "/^git:/", "")} --quiet", + "git clone ${var.install_playbook_repo} --quiet", "cd ocp4-playbooks && git checkout ${var.install_playbook_tag}" ] } @@ -103,7 +103,7 @@ resource "null_resource" "prep_playbooks_tools_curl" { triggers = { worker_count = length(var.worker_ips) } - count = length(regexall("^http:|^https:", var.install_playbook_repo)) > 0 ? 1 : 0 + count = length(regexall("\\.zip$", var.install_playbook_repo)) > 0 ? 1 : 0 connection { type = "ssh" @@ -119,11 +119,11 @@ resource "null_resource" "prep_playbooks_tools_curl" { inline = [ "rm -rf ocp4-playbooks", "echo 'Downloading ocp4-playbooks...'", - "curl -o ocp4-playbooks.tar.gz ${var.install_playbook_repo}", + "curl -o ocp4-playbooks.zip ${var.install_playbook_repo}", "echo 'Extracting ocp4-playbooks...'", - "tar zxvf ocp4-playbooks.tar.gz", - "rm ocp4-playbooks.tar.gz", - "cd ocp4-playbooks && git checkout ${var.install_playbook_tag}" + "unzip ocp4-playbooks.tar.gz", + "mv ocp4-playbooks-master ocp4-playbooks", + "rm ocp4-playbooks.tar.gz" ] } } diff --git a/var.tfvars b/var.tfvars index 6985e275df..18e4a48f3c 100644 --- a/var.tfvars +++ b/var.tfvars @@ -57,9 +57,9 @@ cluster_id = "" # It will use random generated id with #release_image_override = "" -#helpernode_repo = "git:https://github.com/RedHatOfficial/ocp4-helpernode" +#helpernode_repo = "https://github.com/RedHatOfficial/ocp4-helpernode" #helpernode_tag = "" -#install_playbook_repo = "git:https://github.com/ocp-power-automation/ocp4-playbooks" +#install_playbook_repo = "https://github.com/ocp-power-automation/ocp4-playbooks" #install_playbook_tag = "" #helm_repo = "https://get.helm.sh/helm-v3.4.0-linux-ppc64le.tar.gz" diff --git a/variables.tf b/variables.tf index f86fd7e802..8d699f4494 100644 --- a/variables.tf +++ b/variables.tf @@ -257,7 +257,7 @@ variable "installer_log_level" { variable "helpernode_repo" { description = "Set the repo URL for using ocp4-helpernode" # Repo for running ocp4 helpernode setup steps. - default = "git:https://github.com/RedHatOfficial/ocp4-helpernode" + default = "https://github.com/RedHatOfficial/ocp4-helpernode" } variable "helpernode_tag" { @@ -269,7 +269,7 @@ variable "helpernode_tag" { variable "install_playbook_repo" { description = "Set the repo URL for using ocp4-playbooks" # Repo for running ocp4 installations steps. - default = "git:https://github.com/ocp-power-automation/ocp4-playbooks" + default = "https://github.com/ocp-power-automation/ocp4-playbooks" } variable "install_playbook_tag" {