From 0e583ae7aad4a53e1710d68e2c2a850538c69f78 Mon Sep 17 00:00:00 2001 From: hdamecharla Date: Thu, 7 Dec 2023 22:59:08 +0530 Subject: [PATCH] changes to the configure_deployer shell and template --- deploy/scripts/configure_deployer.sh | 122 +++++++++--------- .../templates/configure_deployer.sh.tmpl | 83 ++++++------ 2 files changed, 107 insertions(+), 98 deletions(-) diff --git a/deploy/scripts/configure_deployer.sh b/deploy/scripts/configure_deployer.sh index e0e506e201..d414fb942e 100755 --- a/deploy/scripts/configure_deployer.sh +++ b/deploy/scripts/configure_deployer.sh @@ -140,7 +140,7 @@ pkg_mgr_init() pkg_type="rpm" ;; (*) - error "Unsupported distibution: '$${distro_name}'" + error "Unsupported distibution: '${distro_name}'" exit 1 ;; esac @@ -160,15 +160,15 @@ pkg_mgr_refresh() case ${pkg_mgr} in (apt-get) - sudo ${pkg_mgr} update --quiet + sudo "${pkg_mgr}" update --quiet ;; (zypper) set +o errexit - sudo ${pkg_mgr} --gpg-auto-import-keys --quiet refresh + sudo "${pkg_mgr}" --gpg-auto-import-keys --quiet refresh set -o errexit ;; (yum) - sudo ${pkg_mgr} update --quiet + sudo "${pkg_mgr}" update --quiet ;; esac @@ -190,15 +190,15 @@ pkg_mgr_upgrade() case ${pkg_mgr} in (apt-get) - sudo ${pkg_mgr} upgrade --quiet -y + sudo "${pkg_mgr}" upgrade --quiet -y ;; (zypper) set +o errexit - sudo ${pkg_mgr} --gpg-auto-import-keys --non-interactive patch + sudo "${pkg_mgr}" --gpg-auto-import-keys --non-interactive patch set -o errexit ;; (yum) - sudo ${pkg_mgr} upgrade --quiet -y + sudo "${pkg_mgr}" upgrade --quiet -y ;; esac @@ -223,7 +223,7 @@ pkg_mgr_install() set -o errexit ;; (yum) - sudo ${pkg_mgr} --nogpgcheck --quiet install --assumeyes "${@}" + sudo "${pkg_mgr}" --nogpgcheck --quiet install --assumeyes "${@}" ;; esac } @@ -235,11 +235,11 @@ pkg_mgr_install() # Ansible installation directories ansible_base=/opt/ansible -ansible_bin=${ansible_base}/bin -ansible_venv=${ansible_base}/venv/${ansible_version} -ansible_venv_bin=${ansible_venv}/bin -ansible_collections=${ansible_base}/collections -ansible_pip3=${ansible_venv_bin}/pip3 +ansible_bin="${ansible_base}/bin" +ansible_venv="${ansible_base}/venv/${ansible_version}" +ansible_venv_bin="${ansible_venv}/bin" +ansible_collections="${ansible_base}/collections" +ansible_pip3="${ansible_venv_bin}/pip3" # Azure SAP Automated Deployment directories asad_home="${HOME}/Azure_SAP_Automated_Deployment" @@ -251,9 +251,9 @@ asad_sample_dir="${asad_home}/samples" # Terraform installation directories tf_base=/opt/terraform -tf_dir=${tf_base}/terraform_${tfversion} -tf_bin=${tf_base}/bin -tf_zip=terraform_${tfversion}_linux_amd64.zip +tf_dir="${tf_base}/terraform_${tfversion}" +tf_bin="${tf_base}/bin" +tf_zip="terraform_${tfversion}_linux_amd64.zip" # #Don't re-run the following if the script is already installed @@ -266,27 +266,27 @@ tf_zip=terraform_${tfversion}_linux_amd64.zip # Check for supported distro case "$(get_distro_name_version)" in (sles_12*) - error "Unsupported distro: $${distro_name_version} doesn't provide virtualenv in standard repos." + error "Unsupported distro: ${distro_name_version} doesn't provide virtualenv in standard repos." exit 1 ;; (ubuntu*|sles*) - echo "$${distro_name_version} is supported." + echo "${distro_name_version} is supported." ;; (rhel*) - echo "$${distro_name_version} is supported." + echo "${distro_name_version} is supported." ;; (*) - error "Unsupported distro: $${distro_name_version} not currently supported." + error "Unsupported distro: ${distro_name_version} not currently supported." exit 1 ;; esac if [ "$(get_distro_version)" == "15.4" ]; then - error "Unsupported distro: $${distro_name_version} at this time." + error "Unsupported distro: ${distro_name_version} at this time." exit 1 fi if [ "$(get_distro_version)" == "15.5" ]; then - error "Unsupported distro: $${distro_name_version} at this time." + error "Unsupported distro: ${distro_name_version} at this time." exit 1 fi @@ -306,9 +306,9 @@ case "$(get_distro_name)" in echo "we are inside ubuntu" rel=$(lsb_release -a | grep Release | cut -d':' -f2 | xargs) if [ "$rel" == "22.04" ]; then - ansible_version="$${ansible_version:-2.15}" - ansible_major="$${ansible_version%%.*}" - ansible_minor=$(echo "$${ansible_version}." | cut -d . -f 2) + ansible_version="${ansible_version:-2.15}" + ansible_major="${ansible_version%%.*}" + ansible_minor=$(echo "${ansible_version}." | cut -d . -f 2) fi ;; (sles) @@ -344,7 +344,7 @@ case "$(get_distro_name)" in ;; esac -echo "Ansible version: $${ansible_version}" +echo "Ansible version: ${ansible_version}" # List of required packages whose names are common to all supported distros required_pkgs=( git @@ -424,11 +424,11 @@ subscription_id=$(curl -H Metadata:true --noproxy "*" "http://169.254.169.254/me # Prepare Azure SAP Automated Deployment folder structure mkdir -p \ - ${asad_ws}/LOCAL/${rg_name} \ - ${asad_ws}/LIBRARY \ - ${asad_ws}/SYSTEM \ - ${asad_ws}/LANDSCAPE \ - ${asad_ws}/DEPLOYER + "${asad_ws}"/LOCAL/"${rg_name}" \ + "${asad_ws}"/LIBRARY \ + "${asad_ws}"/SYSTEM \ + "${asad_ws}"/LANDSCAPE \ + "${asad_ws}"/DEPLOYER # # Clone Azure SAP Automated Deployment code repository @@ -448,11 +448,11 @@ fi # Install terraform for all users # sudo mkdir -p \ - ${tf_dir} \ - ${tf_bin} -wget -nv -O /tmp/${tf_zip} https://releases.hashicorp.com/terraform/${tfversion}/${tf_zip} -sudo unzip -o /tmp/${tf_zip} -d ${tf_dir} -sudo ln -vfs ../$(basename ${tf_dir})/terraform ${tf_bin}/terraform + "${tf_dir}" \ + "${tf_bin}" +wget -nv -O /tmp/"${tf_zip}" "https://releases.hashicorp.com/terraform/${tfversion}/${tf_zip}" +sudo unzip -o /tmp/"${tf_zip}" -d "${tf_dir}" +sudo ln -vfs "../$(basename "${tf_dir}")/terraform" "${tf_bin}/terraform" # Uninstall Azure CLI - For some platforms case "$(get_distro_name)" in @@ -501,7 +501,7 @@ case "$(get_distro_name)" in ;; (sles) set +o errexit - if [ -f /home/${local_user}/repos_configured ]; then + if [ -f /home/"${local_user}"/repos_configured ]; then sudo zypper install -y --from azure-cli azure-cli else sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc @@ -538,19 +538,19 @@ case "$(get_distro_name)" in (sles) sudo wget https://dot.net/v1/dotnet-install.sh -O "/home/${local_user}/dotnet-install.sh" sudo chmod +x "/home/${local_user}/dotnet-install.sh" - sudo /home/${local_user}/dotnet-install.sh --install-dir "${DOTNET_ROOT}" --channel 7.0 + sudo /home/"${local_user}"/dotnet-install.sh --install-dir "${DOTNET_ROOT}" --channel 7.0 ;; (rhel*) sudo wget https://dot.net/v1/dotnet-install.sh -O "/home/${local_user}/dotnet-install.sh" sudo chmod +x "/home/${local_user}/dotnet-install.sh" - sudo /home/${local_user}/dotnet-install.sh --install-dir "${DOTNET_ROOT}" --channel 7.0 + sudo /home/"${local_user}"/dotnet-install.sh --install-dir "${DOTNET_ROOT}" --channel 7.0 ;; esac az config set extension.use_dynamic_install=yes_without_prompt devops_extension_installed=$(az extension list --query "[?name=='azure-devops'].name | [0]") -if [ -z $devops_extension_installed ]; then +if [ -z "$devops_extension_installed" ]; then az extension add --name azure-devops --output none fi @@ -565,22 +565,22 @@ set -o errexit # sudo mkdir -p \ - ${ansible_bin} \ - ${ansible_collections} + "${ansible_bin}" \ + "${ansible_collections}" # Create a Python3 based venv into which we will install Ansible. case "$(get_distro_name)" in (ubuntu|sles) if [[ ! -e "${ansible_venv_bin}/activate" ]]; then - sudo rm -rf ${ansible_venv} - sudo virtualenv --python python3 ${ansible_venv} + sudo rm -rf "${ansible_venv}" + sudo virtualenv --python python3 "${ansible_venv}" fi ;; (rhel*) if [[ ! -e "${ansible_venv_bin}/activate" ]]; then - sudo rm -rf ${ansible_venv} - sudo python3 -m venv ${ansible_venv} + sudo rm -rf "${ansible_venv}" + sudo python3 -m venv "${ansible_venv}" source "${ansible_venv_bin}/activate" fi ;; @@ -596,7 +596,7 @@ fi # Ensure that standard tools are up to date -sudo ${ansible_venv_bin}/pip3 install --upgrade \ +sudo "${ansible_venv_bin}"/pip3 install --upgrade \ pip \ wheel \ setuptools @@ -614,7 +614,7 @@ sudo ${ansible_venv_bin}/pip3 install --upgrade \ # ansible-lint \ # yamllint \ -sudo ${ansible_venv_bin}/pip3 install \ +sudo "${ansible_venv_bin}"/pip3 install \ "ansible-core>=${ansible_major}.${ansible_minor},<${ansible_major}.$((ansible_minor + 1))" \ argcomplete \ 'pywinrm>=0.3.0' \ @@ -652,18 +652,18 @@ ansible_venv_commands=( ) -relative_path="$(realpath --relative-to ${ansible_bin} ${ansible_venv_bin})" +relative_path="$(realpath --relative-to ${ansible_bin} "${ansible_venv_bin}")" for vcmd in "${ansible_venv_commands[@]}" do - sudo ln -vfs ${relative_path}/${vcmd} ${ansible_bin}/${vcmd} + sudo ln -vfs "${relative_path}/${vcmd}" "${ansible_bin}/${vcmd}" done # Ensure that Python argcomplete is enabled for all users interactive shell sessions -sudo ${ansible_bin}/activate-global-python-argcomplete +sudo "${ansible_bin}"/activate-global-python-argcomplete # Install Ansible collections under the ANSIBLE_COLLECTIONS_PATHS for all users. -sudo mkdir -p ${ansible_collections} +sudo mkdir -p "${ansible_collections}" set +o xtrace sudo -H "${ansible_venv_bin}/ansible-galaxy" collection install ansible.windows --force --collections-path "${ansible_collections}" @@ -694,11 +694,11 @@ export PATH="${PATH}":"${ansible_bin}":"${tf_bin}":"${DOTNET_ROOT}" # Prepare Azure SAP Automated Deployment folder structure mkdir -p \ - ${asad_ws}/LOCAL/${rg_name} \ - ${asad_ws}/LIBRARY \ - ${asad_ws}/SYSTEM \ - ${asad_ws}/LANDSCAPE \ - ${asad_ws}/DEPLOYER/${rg_name} + "${asad_ws}"/LOCAL/"${rg_name}" \ + "${asad_ws}"/LIBRARY \ + "${asad_ws}"/SYSTEM \ + "${asad_ws}"/LANDSCAPE \ + "${asad_ws}"/DEPLOYER/"${rg_name}" chown -R "${USER}" "${asad_ws}" @@ -711,15 +711,15 @@ echo '# Configure environment settings for deployer interactive session' # Add new /opt bin directories to start of PATH to ensure the versions we installed # are preferred over any installed standard system versions. -export ARM_SUBSCRIPTION_ID=${subscription_id} -export DEPLOYMENT_REPO_PATH=$HOME/Azure_SAP_Automated_Deployment/sap-automation +export ARM_SUBSCRIPTION_ID="${subscription_id}" +export DEPLOYMENT_REPO_PATH="$HOME/Azure_SAP_Automated_Deployment/sap-automation" # Add new /opt bin directories to start of PATH to ensure the versions we installed # are preferred over any installed standard system versions. # Set env for ansible export ANSIBLE_HOST_KEY_CHECKING=False -export ANSIBLE_COLLECTIONS_PATHS=~/.ansible/collections:${ansible_collections} +export ANSIBLE_COLLECTIONS_PATHS=~/.ansible/collections:"${ansible_collections}" # Set env for MSI export ARM_USE_MSI=true @@ -789,7 +789,7 @@ fi # Ensure that the user's account is logged in to Azure with specified creds -echo "az login --identity --output none" | tee -a /tmp/deploy_server.sh +echo 'az login --identity --output none' | tee -a /tmp/deploy_server.sh echo 'echo ${USER} account ready for use with Azure SAP Automated Deployment' | tee -a /tmp/deploy_server.sh sudo cp /tmp/deploy_server.sh /etc/profile.d/deploy_server.sh diff --git a/deploy/terraform/terraform-units/modules/sap_deployer/templates/configure_deployer.sh.tmpl b/deploy/terraform/terraform-units/modules/sap_deployer/templates/configure_deployer.sh.tmpl index f23060a709..f29ffd606b 100644 --- a/deploy/terraform/terraform-units/modules/sap_deployer/templates/configure_deployer.sh.tmpl +++ b/deploy/terraform/terraform-units/modules/sap_deployer/templates/configure_deployer.sh.tmpl @@ -293,6 +293,7 @@ else exit 1 ;; esac + if [ "$(get_distro_version)" == "15.4" ]; then error "Unsupported distro: $${distro_name_version} at this time." exit 1 @@ -305,6 +306,7 @@ else echo "Set ansible version for specific distros" echo "" + case "$(get_distro_name)" in (ubuntu) echo "we are inside ubuntu" @@ -317,31 +319,31 @@ else ;; (sles) echo "we are inside sles" - if [ "$(get_distro_version)" == "15.3" ]; then - ansible_version="2.11" - ansible_major="$${ansible_version%%.*}" - ansible_minor=$(echo "$${ansible_version}." | cut -d . -f 2) - # Ansible installation directories - ansible_base="/opt/ansible" - ansible_bin="$${ansible_base}/bin" - ansible_venv="$${ansible_base}/venv/$${ansible_version}" - ansible_venv_bin="$${ansible_venv}/bin" - ansible_collections="$${ansible_base}/collections" - ansible_pip3="$${ansible_venv_bin}/pip3" - sudo python3 -m pip install virtualenv; - elif [ "$(get_distro_version)" == "15.5" ]; then - ansible_version="2.11" - ansible_major="$${ansible_version%%.*}" - ansible_minor=$(echo "$${ansible_version}." | cut -d . -f 2) - # Ansible installation directories - ansible_base="/opt/ansible" - ansible_bin="$${ansible_base}/bin" - ansible_venv="$${ansible_base}/venv/$${ansible_version}" - ansible_venv_bin="$${ansible_venv}/bin" - ansible_collections="$${ansible_base}/collections" - ansible_pip3="$${ansible_venv_bin}/pip3" - sudo python3 -m pip install virtualenv; - fi + ansible_version="2.11" + ansible_major="$${ansible_version%%.*}" + ansible_minor=$(echo "$${ansible_version}." | cut -d . -f 2) + # Ansible installation directories + ansible_base="/opt/ansible" + ansible_bin="$${ansible_base}/bin" + ansible_venv="$${ansible_base}/venv/$${ansible_version}" + ansible_venv_bin="$${ansible_venv}/bin" + ansible_collections="$${ansible_base}/collections" + ansible_pip3="$${ansible_venv_bin}/pip3" + sudo python3 -m pip install virtualenv; + ;; + (rhel) + echo "we are inside RHEL" + ansible_version="2.11" + ansible_major="$${ansible_version%%.*}" + ansible_minor=$(echo "$${ansible_version}." | cut -d . -f 2) + # Ansible installation directories + ansible_base="/opt/ansible" + ansible_bin="$${ansible_base}/bin" + ansible_venv="$${ansible_base}/venv/$${ansible_version}" + ansible_venv_bin="$${ansible_venv}/bin" + ansible_collections="$${ansible_base}/collections" + ansible_pip3="$${ansible_venv_bin}/pip3" + sudo python3 -m pip install virtualenv; ;; (*) echo "we are in the default case statement" @@ -491,20 +493,24 @@ else sudo apt-get install azure-cli -y ;; (sles) - if [ -f /home/$${local_user}/repos_configured ]; then + set +o errexit + if [ -f /home/"$${local_user}"/repos_configured ]; then sudo zypper install -y --from azure-cli azure-cli else sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc - sudo zypper addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli + repo_found=$(zypper repos | grep "Azure CLI") + if [ -z "$${repo_found}" ]; then + sudo zypper addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli + fi sudo touch /home/$${local_user}/repos_configured sudo zypper install -y --from azure-cli azure-cli fi - + set -o errexit ;; (rhel*) sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm - sudo dnf install azure-cli + sudo dnf install -y azure-cli ;; esac @@ -538,9 +544,11 @@ else case "$(get_distro_name)" in (rhel) - sudo python -m venv "$${ansible_venv}" - source "$${ansible_venv_bin}/activate" - + if [[ ! -e "$${ansible_venv_bin}/activate" ]]; then + sudo rm -rf "$${ansible_venv}" + sudo python3 -m venv "$${ansible_venv}" + source "$${ansible_venv_bin}/activate" + fi ;; (ubuntu|sles) # Create a Python3 based venv into which we will install Ansible. @@ -669,17 +677,18 @@ else echo export ANSIBLE_HOST_KEY_CHECKING=False | sudo tee -a /etc/profile.d/deploy_server.sh echo export ANSIBLE_COLLECTIONS_PATHS="$${ansible_collections}" | sudo tee -a /etc/profile.d/deploy_server.sh - export DOTNET_INSTALL_DIR=/opt/dotnet + export DOTNET_INSTALL_DIR='/opt/dotnet' - sudo mkdir -p $${DOTNET_INSTALL_DIR} + sudo mkdir -p "$${DOTNET_INSTALL_DIR}" case "$(get_distro_name)" in (ubuntu) echo "export DOTNET_ROOT=/snap/dotnet-sdk/current" | tee -a /tmp/deploy_server.sh + export DOTNET_ROOT='/snap/dotnet-sdk/current' ;; (sles) echo "export DOTNET_ROOT=$${DOTNET_INSTALL_DIR}" | tee -a /tmp/deploy_server.sh - export DOTNET_ROOT=$${DOTNET_INSTALL_DIR} + export DOTNET_ROOT="$${DOTNET_INSTALL_DIR}" ;; (rhel*) ;; @@ -702,10 +711,10 @@ else # Add new /opt bin directories to start of PATH to ensure the versions we installed # are preferred over any installed standard system versions. - echo export "PATH=$${ansible_bin}:$${tf_bin}:"'$${PATH}'::"$${DOTNET_ROOT}":'$${AZADHOME}/Azure_SAP_Automated_Deployment/sap-automation/deploy/scripts' | sudo tee -a /etc/profile.d/deploy_server.sh + echo export "PATH=$${ansible_bin}:$${tf_bin}:$${PATH}":"$${DOTNET_ROOT}":"$${AZADHOME}/Azure_SAP_Automated_Deployment/sap-automation/deploy/scripts" | sudo tee -a /etc/profile.d/deploy_server.sh # Ensure that the user's account is logged in to Azure with specified creds - echo az login --identity --allow-no-subscriptions --output none | sudo tee -a /etc/profile.d/deploy_server.sh + echo 'az login --identity --allow-no-subscriptions --output none' | sudo tee -a /etc/profile.d/deploy_server.sh echo 'echo $${USER} account ready for use with Azure SAP Automated Deployment' | sudo tee -a /etc/profile.d/deploy_server.sh sudo runuser -l "$${local_user}" -c '/usr/bin/az login --identity --allow-no-subscriptions --output none'