From e4ce1b867929f33acc361930dcbafb90e131f6ef Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Wed, 12 Jun 2024 19:05:36 +0200 Subject: [PATCH] Install ansible inside a venv instead of globally Help reducing potential conflicts with metal3-dev-env. --- 01_install_requirements.sh | 18 ++++++++++-------- 02_configure_host.sh | 4 ++-- agent/05_agent_configure.sh | 2 +- common.sh | 2 ++ host_cleanup.sh | 2 +- network.sh | 2 +- remote_nodes.sh | 2 +- utils.sh | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/01_install_requirements.sh b/01_install_requirements.sh index 774b95102..d19f727c7 100755 --- a/01_install_requirements.sh +++ b/01_install_requirements.sh @@ -19,7 +19,7 @@ if [ -z "${METAL3_DEV_ENV}" ]; then # TODO -- come up with a plan for continuously updating this # Note we only do this in the case where METAL3_DEV_ENV is # unset, to enable developer testing of local checkouts - git reset a994b1447f89e20ec9cc161700a9e829fd5d4b89 --hard + git reset d9fc324e8a37935b6c1b4555b5a8724b29626259 --hard popd fi @@ -113,16 +113,15 @@ elif [[ $GOARCH == "x86_64" ]]; then GOARCH="amd64" fi -# Also need the 3.9 version of netaddr for ansible.netcommon -# and lxml for the pyxpath script -sudo python -m pip install netaddr lxml +sudo python -m venv --system-site-packages "${ANSIBLE_VENV}" -sudo python -m pip install ansible=="${ANSIBLE_VERSION}" +# Also need the 3.9 version of netaddr for ansible.netcommon +"${ANSIBLE_VENV}/bin/pip" install netaddr ansible=="${ANSIBLE_VERSION}" pushd ${METAL3_DEV_ENV_PATH} -ansible-galaxy install -r vm-setup/requirements.yml -ansible-galaxy collection install --upgrade ansible.netcommon ansible.posix ansible.utils community.general -ANSIBLE_FORCE_COLOR=true ansible-playbook \ +"${ANSIBLE}-galaxy" install -r vm-setup/requirements.yml +"${ANSIBLE}-galaxy" collection install --upgrade ansible.netcommon ansible.posix ansible.utils community.general +ANSIBLE_FORCE_COLOR=true "${ANSIBLE}-playbook" \ -e "working_dir=$WORKING_DIR" \ -e "virthost=$HOSTNAME" \ -e "go_version=$GO_VERSION" \ @@ -146,6 +145,9 @@ if [[ "${NODES_PLATFORM}" == "baremetal" ]] ; then sudo dnf -y install ipmitool fi +# lxml is needed for our pyxpath tool +sudo dnf -y install python3-lxml + # We use yq in a few places for processing YAML but it isn't packaged # for CentOS/RHEL so we have to install from pip. We do not want to # overwrite an existing installation of the golang version, though, diff --git a/02_configure_host.sh b/02_configure_host.sh index 15caa4885..b1fdaee4f 100755 --- a/02_configure_host.sh +++ b/02_configure_host.sh @@ -127,7 +127,7 @@ if [[ $(uname -m) == "aarch64" ]]; then echo "libvirt_cdrombus: scsi" >> vm_setup_vars.yml fi -ansible-playbook \ +"${ANSIBLE}-playbook" \ -e @vm_setup_vars.yml \ -e "ironic_prefix=${CLUSTER_NAME}_" \ -e "cluster_name=${CLUSTER_NAME}" \ @@ -327,7 +327,7 @@ if [[ "$(ipversion $PROVISIONING_HOST_IP)" == "6" ]]; then IPTABLES=ip6tables fi -ANSIBLE_FORCE_COLOR=true ansible-playbook \ +ANSIBLE_FORCE_COLOR=true "${ANSIBLE}-playbook" \ -e "{use_firewalld: True}" \ -e "provisioning_interface=$PROVISIONING_NETWORK_NAME" \ -e "external_interface=$BAREMETAL_NETWORK_NAME" \ diff --git a/agent/05_agent_configure.sh b/agent/05_agent_configure.sh index 19bc50e1e..bf2b5cdba 100755 --- a/agent/05_agent_configure.sh +++ b/agent/05_agent_configure.sh @@ -263,7 +263,7 @@ function generate_cluster_manifests() { set -x # Create manifests - ansible-playbook -vvv \ + "${ANSIBLE}-playbook" -vvv \ -e install_path=${SCRIPTDIR}/${INSTALL_CONFIG_PATH} \ "${SCRIPTDIR}/agent/create-manifests-playbook.yaml" } diff --git a/common.sh b/common.sh index 66ac6250a..6a41ba301 100644 --- a/common.sh +++ b/common.sh @@ -94,6 +94,8 @@ export PROVISIONING_HOST_USER=${PROVISIONING_HOST_USER:-$USER} # The dev-scripts working directory export WORKING_DIR=${WORKING_DIR:-"/opt/dev-scripts"} OCP_DIR=${OCP_DIR:-ocp/${CLUSTER_NAME}} +ANSIBLE_VENV=${ANSIBLE_VENV:-"${WORKING_DIR}/venv"} +ANSIBLE="${ANSIBLE_VENV}/bin/ansible" # The DNS name for the registry that this cluster should use. export LOCAL_REGISTRY_DNS_NAME=${LOCAL_REGISTRY_DNS_NAME:-"virthost.${CLUSTER_NAME}.${BASE_DOMAIN}"} diff --git a/host_cleanup.sh b/host_cleanup.sh index 9347a18ce..4e73ba141 100755 --- a/host_cleanup.sh +++ b/host_cleanup.sh @@ -15,7 +15,7 @@ fi export ANSIBLE_FORCE_COLOR=true -ansible-playbook \ +"${ANSIBLE}-playbook" \ -e @vm_setup_vars.yml \ -e "ironic_prefix=${CLUSTER_NAME}_" \ -e "cluster_name=${CLUSTER_NAME}" \ diff --git a/network.sh b/network.sh index 5efef0d19..f5d6ae14f 100755 --- a/network.sh +++ b/network.sh @@ -6,7 +6,7 @@ function nth_ip() { network=$1 idx=$2 - python -c "from ansible_collections.ansible.utils.plugins.filter import nthhost; print(nthhost.nthhost('"$network"', $idx))" + "${ANSIBLE_VENV}/bin/python" -c "from ansible_collections.ansible.utils.plugins.filter import nthhost; print(nthhost.nthhost('"$network"', $idx))" } function ipversion(){ diff --git a/remote_nodes.sh b/remote_nodes.sh index 597c71908..d3cdd51cf 100644 --- a/remote_nodes.sh +++ b/remote_nodes.sh @@ -68,7 +68,7 @@ function playbook() { VIRTBMC_ACTION="ignore" fi - ansible-playbook \ + "${ANSIBLE}-playbook" \ -e @vm_setup_vars.yml \ -e "ironic_prefix=${REMOTE_CLUSTER_NAME}_" \ -e "cluster_name=${REMOTE_CLUSTER_NAME}" \ diff --git a/utils.sh b/utils.sh index 4bd08c911..b36758f39 100755 --- a/utils.sh +++ b/utils.sh @@ -787,7 +787,7 @@ function write_pull_secret() { function switch_to_internal_dns() { sudo mkdir -p /etc/NetworkManager/conf.d/ - ansible localhost -b -m ini_file -a "path=/etc/NetworkManager/conf.d/dnsmasq.conf section=main option=dns value=dnsmasq" + "${ANSIBLE}" localhost -b -m ini_file -a "path=/etc/NetworkManager/conf.d/dnsmasq.conf section=main option=dns value=dnsmasq" if [ "$ADDN_DNS" ] ; then echo "server=$ADDN_DNS" | sudo tee /etc/NetworkManager/dnsmasq.d/upstream.conf fi