<commit_before>#!/bin/bash
set -eu

. $(dirname $0)/install-deps.sh
# NOTE(pas-ha) the above exports some useful variables like
# $PYTHON , $PIP and $VENV depending on venv install or not

DEFAULT_PIP_ANSIBLE='>=2.9,<2.10'

ANSIBLE_PIP_VERSION=${ANSIBLE_PIP_VERSION:-${DEFAULT_PIP_ANSIBLE}}
ANSIBLE_SOURCE_PATH=${ANSIBLE_SOURCE_PATH:-ansible${ANSIBLE_PIP_VERSION}}
ANSIBLE_COLLECTION_REQ=${ANSIBLE_COLLECTION_REQ:-$(dirname $0)/../ansible-collection-requirements.yml}
BIFROST_COLLECTIONS_PATHS=${ANSIBLE_COLLECTIONS_PATHS:-}

if [ -n "${VENV-}" ]; then
    ${PIP} install "${ANSIBLE_SOURCE_PATH}"
    ANSIBLE=${VENV}/bin/ansible
    ANSIBLE_GALAXY=${VENV}/bin/ansible-galaxy
    if [[ -z $BIFROST_COLLECTIONS_PATHS ]]; then
        echo  "Setting ANSIBLE_COLLECTIONS_PATHS to virtualenv"
        export ANSIBLE_COLLECTIONS_PATHS=${VENV}/collections
        BIFROST_COLLECTIONS_PATHS=$ANSIBLE_COLLECTIONS_PATHS
    fi
else
    ${PIP} install --user --upgrade "${ANSIBLE_SOURCE_PATH}"
    ANSIBLE=${HOME}/.local/bin/ansible
    ANSIBLE_GALAXY=${HOME}/.local/bin/ansible-galaxy
fi

PLAYBOOKS_LIBRARY_PATH=$(dirname $0)/../playbooks/library

# NOTE(pas-ha) the following is a temporary workaround for third-party CI
# scripts that try to source Ansible's hacking/env-setup
# after running this very script
# TODO(pas-ha) remove after deprecation (in Pike?) and when third-party CIs
# (in particular OPNFV) are fixed
ANSIBLE_INSTALL_ROOT=${ANSIBLE_INSTALL_ROOT:-/opt/stack}
u=$(whoami)
g=$(groups | awk '{print $1}')
if [ ! -d ${ANSIBLE_INSTALL_ROOT} ]; then
    mkdir -p ${ANSIBLE_INSTALL_ROOT} || (sudo mkdir -p ${ANSIBLE_INSTALL_ROOT})
fi
sudo -H chown -R $u:$g ${ANSIBLE_INSTALL_ROOT}


# Install Collections
if [[ -z $BIFROST_COLLECTIONS_PATHS ]];
then
    echo "Installing ansible collections on default collections path"
    ${ANSIBLE_GALAXY} collection install -r ${ANSIBLE_COLLECTION_REQ}
else<commit_msg>Support installing the openstack collection from a local location<commit_after>#!/bin/bash
set -eu

. $(dirname $0)/install-deps.sh
# NOTE(pas-ha) the above exports some useful variables like
# $PYTHON , $PIP and $VENV depending on venv install or not

DEFAULT_PIP_ANSIBLE='>=2.9,<2.10'

ANSIBLE_PIP_VERSION=${ANSIBLE_PIP_VERSION:-${DEFAULT_PIP_ANSIBLE}}
ANSIBLE_SOURCE_PATH=${ANSIBLE_SOURCE_PATH:-ansible${ANSIBLE_PIP_VERSION}}
ANSIBLE_COLLECTION_SOURCE_PATH=
if [[ -d "${WORKSPACE:-}/openstack/ansible-collections-openstack" ]]; then
    ANSIBLE_COLLECTION_SOURCE_PATH="${WORKSPACE}/openstack/ansible-collections-openstack"
fi
ANSIBLE_COLLECTION_REQ=${ANSIBLE_COLLECTION_REQ:-$(dirname $0)/../ansible-collection-requirements.yml}
BIFROST_COLLECTIONS_PATHS=${ANSIBLE_COLLECTIONS_PATHS:-}

if [ -n "${VENV-}" ]; then
    ${PIP} install "${ANSIBLE_SOURCE_PATH}"
    ANSIBLE=${VENV}/bin/ansible
    ANSIBLE_GALAXY=${VENV}/bin/ansible-galaxy
    if [[ -z $BIFROST_COLLECTIONS_PATHS ]]; then
        echo  "Setting ANSIBLE_COLLECTIONS_PATHS to virtualenv"
        export ANSIBLE_COLLECTIONS_PATHS=${VENV}/collections
        BIFROST_COLLECTIONS_PATHS=$ANSIBLE_COLLECTIONS_PATHS
    fi
    if [[ -n "$ANSIBLE_COLLECTION_SOURCE_PATH" ]]; then
        mkdir -p "$BIFROST_COLLECTIONS_PATHS/ansible_collections/openstack"
        ln -s "$ANSIBLE_COLLECTION_SOURCE_PATH" "$BIFROST_COLLECTIONS_PATHS/ansible_collections/openstack/cloud"
    fi
else
    ${PIP} install --user --upgrade "${ANSIBLE_SOURCE_PATH}"
    ANSIBLE=${HOME}/.local/bin/ansible
    ANSIBLE_GALAXY=${HOME}/.local/bin/ansible-galaxy
fi

PLAYBOOKS_LIBRARY_PATH=$(dirname $0)/../playbooks/library

# NOTE(pas-ha) the following is a temporary workaround for third-party CI
# scripts that try to source Ansible's hacking/env-setup
# after running this very script
# TODO(pas-ha) remove after deprecation (in Pike?) and when third-party CIs
# (in particular OPNFV) are fixed
ANSIBLE_INSTALL_ROOT=${ANSIBLE_INSTALL_ROOT:-/opt/stack}
u=$(whoami)
g=$(groups | awk '{print $1}')
if [ ! -d ${ANSIBLE_INSTALL_ROOT} ]; then
    mkdir -p ${ANSIBLE_INSTALL_ROOT} || (sudo mkdir -p ${ANSIBLE_INSTALL_ROOT})
fi
sudo -H chown -R $u:$g ${ANSIBLE_INSTALL_ROOT}


# Install Collections
if [[ -n "$ANSIBLE_COLLECTION_SOURCE_PATH" ]]; then
    echo "Using openstack ansible collection from $ANSIBLE_COLLECTION_SOURCE_PATH"
elif [[ -z $BIFROST_COLLECTIONS_PATHS ]]; then
    echo "Installing ansible collections on default collections path"
    ${ANSIBLE_GALAXY} collection install -r ${ANSIBLE_COLLECTION_REQ}
else
{'fraction_non_alphanumeric': 0.1262614936084324, 'fraction_numerical': 0.004036779546983628, 'mean_word_length': 5.3352272727272725, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841142', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1552, 'n_words': 323}