Skip to content

Commit

Permalink
Install ansible inside a venv instead of globally
Browse files Browse the repository at this point in the history
Help reducing potential conflicts with metal3-dev-env.
  • Loading branch information
dtantsur committed Jun 13, 2024
1 parent 3c655f4 commit 2f89a55
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
12 changes: 7 additions & 5 deletions 01_install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,18 @@ elif [[ $GOARCH == "x86_64" ]]; then
GOARCH="amd64"
fi

sudo python -m venv --system-site-packages "${ANSIBLE_VENV}"

# Also need the 3.9 version of netaddr for ansible.netcommon
# and lxml for the pyxpath script
sudo python -m pip install netaddr lxml
"${ANSIBLE_VENV}/bin/pip" install netaddr lxml

sudo python -m pip install ansible=="${ANSIBLE_VERSION}"
"${ANSIBLE_VENV}/bin/pip" install 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" \
Expand Down
4 changes: 2 additions & 2 deletions 02_configure_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down Expand Up @@ -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 "baremetal_interface=$BAREMETAL_NETWORK_NAME" \
Expand Down
2 changes: 1 addition & 1 deletion agent/05_agent_configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 2 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"}
Expand Down
2 changes: 1 addition & 1 deletion host_cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
2 changes: 1 addition & 1 deletion network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
2 changes: 1 addition & 1 deletion remote_nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
2 changes: 1 addition & 1 deletion utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f89a55

Please sign in to comment.