From 5b57f10eeccca16771de76152596fba62a1a7723 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Wed, 10 Jan 2024 15:17:07 +0100 Subject: [PATCH] Add support for extra Python packages inside Ansible runtime At the moment there is no well defined way to supply list of extra Python requirements for Ansible venv. However, some collections for their work might require presence of extra libraries inside the execution environment. While PIP_OPTS might be used right for that, it's usage is not transparent or documented. In order to handle such need, `user-ansible-venv-requirements.txt ` is being implemented that reside inside OSA_CONFIG_DIR and contains list of required packages for installation when running bootstrap-ansible.sh Change-Id: Ic99f7eff200e2e672dcc3edd875b155af84232b7 --- .../reference/configuration/extending-osa.rst | 13 +++++++++++++ .../user-ansible-venv-requirements.txt.example | 5 +++++ .../user_requirements_file-4d9f65599ec4d842.yaml | 8 ++++++++ scripts/bootstrap-ansible.sh | 7 ++++++- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 etc/openstack_deploy/user-ansible-venv-requirements.txt.example create mode 100644 releasenotes/notes/user_requirements_file-4d9f65599ec4d842.yaml diff --git a/doc/source/reference/configuration/extending-osa.rst b/doc/source/reference/configuration/extending-osa.rst index f3c1e18770..9583b080bb 100644 --- a/doc/source/reference/configuration/extending-osa.rst +++ b/doc/source/reference/configuration/extending-osa.rst @@ -93,6 +93,19 @@ You can override location of the ``user-collection-requirements.yml`` by setting ``USER_COLLECTION_FILE`` environment variable before running the ``bootstrap-ansible.sh`` script. +Installing extra Python packages inside Ansible virtualenv +---------------------------------------------------------- + +Some Ansible collections may require presence of specific Python libraries +inside execution environment. +In order to accomplish that deployer can create ``/etc/openstack_deploy/user-ansible-venv-requirements.txt`` +file with a list of Python libraries that should be installed inside virtual +environment along with Ansible during ``bootstrap-ansible.sh`` execution. + +You can override the default path to ``user-ansible-venv-requirements.txt`` file +with ``USER_ANSIBLE_REQUIREMENTS_FILE`` environment variable before running the +``bootstrap-ansible.sh`` script. + Maintaining local forks of ansible roles ---------------------------------------- diff --git a/etc/openstack_deploy/user-ansible-venv-requirements.txt.example b/etc/openstack_deploy/user-ansible-venv-requirements.txt.example new file mode 100644 index 0000000000..82beb5c297 --- /dev/null +++ b/etc/openstack_deploy/user-ansible-venv-requirements.txt.example @@ -0,0 +1,5 @@ +# Use this file to fill in your third party libraries that you'd like to have +# installed inside Ansible virtual environment during bootstrap-ansible.sh. +# This file will be processed additionally to default requirements.txt and +# does not superceed it. +oauthlib>=3.2.0 diff --git a/releasenotes/notes/user_requirements_file-4d9f65599ec4d842.yaml b/releasenotes/notes/user_requirements_file-4d9f65599ec4d842.yaml new file mode 100644 index 0000000000..7448a7efeb --- /dev/null +++ b/releasenotes/notes/user_requirements_file-4d9f65599ec4d842.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Implemented installation of extra Python packages inside Ansible virtual + environment. By default, extra requirements should be defined in + ``/etc/openstack_deploy/user-ansible-venv-requirements.txt`` file. Path to the + requirements file can be overriden using ``USER_ANSIBLE_REQUIREMENTS_FILE`` + environment variable. diff --git a/scripts/bootstrap-ansible.sh b/scripts/bootstrap-ansible.sh index 0ff6e9bd8a..cd10386090 100755 --- a/scripts/bootstrap-ansible.sh +++ b/scripts/bootstrap-ansible.sh @@ -25,8 +25,9 @@ export HTTPS_PROXY=${HTTPS_PROXY:-""} export ANSIBLE_PACKAGE=${ANSIBLE_PACKAGE:-"ansible-core==2.15.5"} export ANSIBLE_ROLE_FILE=${ANSIBLE_ROLE_FILE:-"ansible-role-requirements.yml"} export ANSIBLE_COLLECTION_FILE=${ANSIBLE_COLLECTION_FILE:-"ansible-collection-requirements.yml"} -export USER_ROLE_FILE=${USER_ROLE_FILE:-"user-role-requirements.yml"} export USER_COLLECTION_FILE=${USER_COLLECTION_FILE:-"user-collection-requirements.yml"} +export USER_ANSIBLE_REQUIREMENTS_FILE=${USER_ANSIBLE_REQUIREMENTS_FILE:-"${OSA_CONFIG_DIR:-/etc/openstack_deploy}/user-ansible-venv-requirements.txt"} +export USER_ROLE_FILE=${USER_ROLE_FILE:-"user-role-requirements.yml"} export SSH_DIR=${SSH_DIR:-"/root/.ssh"} export DEBIAN_FRONTEND=${DEBIAN_FRONTEND:-"noninteractive"} # check whether to install the ARA callback plugin @@ -122,6 +123,10 @@ elif [ -n "$HTTP_PROXY" ]; then PIP_OPTS+="--proxy $HTTP_PROXY" fi +if [ -f "${USER_ANSIBLE_REQUIREMENTS_FILE}" ]; then + PIP_OPTS+="--requirement $USER_ANSIBLE_REQUIREMENTS_FILE" +fi + PYTHON_EXEC_PATH="${PYTHON_EXEC_PATH:-$(which python3)}" # Obtain the SHA of the upper-constraints to use for the ansible runtime venv