Skip to content

Commit 2f89a55

Browse files
committed
Install ansible inside a venv instead of globally
Help reducing potential conflicts with metal3-dev-env.
1 parent 3c655f4 commit 2f89a55

8 files changed

+16
-12
lines changed

01_install_requirements.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,18 @@ elif [[ $GOARCH == "x86_64" ]]; then
110110
GOARCH="amd64"
111111
fi
112112

113+
sudo python -m venv --system-site-packages "${ANSIBLE_VENV}"
114+
113115
# Also need the 3.9 version of netaddr for ansible.netcommon
114116
# and lxml for the pyxpath script
115-
sudo python -m pip install netaddr lxml
117+
"${ANSIBLE_VENV}/bin/pip" install netaddr lxml
116118

117-
sudo python -m pip install ansible=="${ANSIBLE_VERSION}"
119+
"${ANSIBLE_VENV}/bin/pip" install ansible=="${ANSIBLE_VERSION}"
118120

119121
pushd ${METAL3_DEV_ENV_PATH}
120-
ansible-galaxy install -r vm-setup/requirements.yml
121-
ansible-galaxy collection install --upgrade ansible.netcommon ansible.posix ansible.utils community.general
122-
ANSIBLE_FORCE_COLOR=true ansible-playbook \
122+
"${ANSIBLE}-galaxy" install -r vm-setup/requirements.yml
123+
"${ANSIBLE}-galaxy" collection install --upgrade ansible.netcommon ansible.posix ansible.utils community.general
124+
ANSIBLE_FORCE_COLOR=true "${ANSIBLE}-playbook" \
123125
-e "working_dir=$WORKING_DIR" \
124126
-e "virthost=$HOSTNAME" \
125127
-e "go_version=$GO_VERSION" \

02_configure_host.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ if [[ $(uname -m) == "aarch64" ]]; then
127127
echo "libvirt_cdrombus: scsi" >> vm_setup_vars.yml
128128
fi
129129

130-
ansible-playbook \
130+
"${ANSIBLE}-playbook" \
131131
-e @vm_setup_vars.yml \
132132
-e "ironic_prefix=${CLUSTER_NAME}_" \
133133
-e "cluster_name=${CLUSTER_NAME}" \
@@ -327,7 +327,7 @@ if [[ "$(ipversion $PROVISIONING_HOST_IP)" == "6" ]]; then
327327
IPTABLES=ip6tables
328328
fi
329329

330-
ANSIBLE_FORCE_COLOR=true ansible-playbook \
330+
ANSIBLE_FORCE_COLOR=true "${ANSIBLE}-playbook" \
331331
-e "{use_firewalld: True}" \
332332
-e "provisioning_interface=$PROVISIONING_NETWORK_NAME" \
333333
-e "baremetal_interface=$BAREMETAL_NETWORK_NAME" \

agent/05_agent_configure.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ function generate_cluster_manifests() {
263263
set -x
264264

265265
# Create manifests
266-
ansible-playbook -vvv \
266+
"${ANSIBLE}-playbook" -vvv \
267267
-e install_path=${SCRIPTDIR}/${INSTALL_CONFIG_PATH} \
268268
"${SCRIPTDIR}/agent/create-manifests-playbook.yaml"
269269
}

common.sh

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export PROVISIONING_HOST_USER=${PROVISIONING_HOST_USER:-$USER}
9494
# The dev-scripts working directory
9595
export WORKING_DIR=${WORKING_DIR:-"/opt/dev-scripts"}
9696
OCP_DIR=${OCP_DIR:-ocp/${CLUSTER_NAME}}
97+
ANSIBLE_VENV=${ANSIBLE_VENV:-"${WORKING_DIR}/venv"}
98+
ANSIBLE="${ANSIBLE_VENV}/bin/ansible"
9799

98100
# The DNS name for the registry that this cluster should use.
99101
export LOCAL_REGISTRY_DNS_NAME=${LOCAL_REGISTRY_DNS_NAME:-"virthost.${CLUSTER_NAME}.${BASE_DOMAIN}"}

host_cleanup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515

1616
export ANSIBLE_FORCE_COLOR=true
1717

18-
ansible-playbook \
18+
"${ANSIBLE}-playbook" \
1919
-e @vm_setup_vars.yml \
2020
-e "ironic_prefix=${CLUSTER_NAME}_" \
2121
-e "cluster_name=${CLUSTER_NAME}" \

network.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function nth_ip() {
66
network=$1
77
idx=$2
88

9-
python -c "from ansible_collections.ansible.utils.plugins.filter import nthhost; print(nthhost.nthhost('"$network"', $idx))"
9+
"${ANSIBLE_VENV}/bin/python" -c "from ansible_collections.ansible.utils.plugins.filter import nthhost; print(nthhost.nthhost('"$network"', $idx))"
1010
}
1111

1212
function ipversion(){

remote_nodes.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function playbook() {
6868
VIRTBMC_ACTION="ignore"
6969
fi
7070

71-
ansible-playbook \
71+
"${ANSIBLE}-playbook" \
7272
-e @vm_setup_vars.yml \
7373
-e "ironic_prefix=${REMOTE_CLUSTER_NAME}_" \
7474
-e "cluster_name=${REMOTE_CLUSTER_NAME}" \

utils.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ function write_pull_secret() {
787787

788788
function switch_to_internal_dns() {
789789
sudo mkdir -p /etc/NetworkManager/conf.d/
790-
ansible localhost -b -m ini_file -a "path=/etc/NetworkManager/conf.d/dnsmasq.conf section=main option=dns value=dnsmasq"
790+
"${ANSIBLE}" localhost -b -m ini_file -a "path=/etc/NetworkManager/conf.d/dnsmasq.conf section=main option=dns value=dnsmasq"
791791
if [ "$ADDN_DNS" ] ; then
792792
echo "server=$ADDN_DNS" | sudo tee /etc/NetworkManager/dnsmasq.d/upstream.conf
793793
fi

0 commit comments

Comments
 (0)