diff --git a/ansible/group_vars/all/kolla b/ansible/group_vars/all/kolla index fc297eb16..a659cf52d 100644 --- a/ansible/group_vars/all/kolla +++ b/ansible/group_vars/all/kolla @@ -40,6 +40,9 @@ kolla_ansible_source_version: "stable/queens" # Path to virtualenv in which to install kolla-ansible. kolla_ansible_venv: "{{ lookup('env', 'KOLLA_VENV_PATH') | default(lookup('env', 'PWD') ~ '/venvs/kolla-ansible', true) }}" +# Extra requirements to install inside the kolla-ansible virtualenv. +kolla_ansible_venv_extra_requirements: [] + # Path to Kolla-ansible configuration directory. kolla_config_path: "{{ lookup('env', 'KOLLA_CONFIG_PATH') | default('/etc/kolla', true) }}" diff --git a/ansible/roles/kolla-ansible/templates/requirements.txt.j2 b/ansible/roles/kolla-ansible/templates/requirements.txt.j2 index c76337300..4868711d0 100644 --- a/ansible/roles/kolla-ansible/templates/requirements.txt.j2 +++ b/ansible/roles/kolla-ansible/templates/requirements.txt.j2 @@ -8,3 +8,8 @@ kolla-ansible=={{ kolla_openstack_release }} # Limit the version of ansible used by kolla-ansible to avoid new releases from # breaking tested code. Changes to this limit should be tested. ansible<2.6 +{% if kolla_ansible_venv_extra_requirements is defined %} +{% for item in kolla_ansible_venv_extra_requirements %} +{{ item }} +{% endfor %} +{% endif %} diff --git a/ansible/roles/kolla-ansible/tests/main.yml b/ansible/roles/kolla-ansible/tests/main.yml index b3fa61a6b..e387e8baf 100644 --- a/ansible/roles/kolla-ansible/tests/main.yml +++ b/ansible/roles/kolla-ansible/tests/main.yml @@ -10,6 +10,7 @@ - include: test-defaults.yml - include: test-extras.yml +- include: test-requirements.yml - hosts: localhost connection: local diff --git a/ansible/roles/kolla-ansible/tests/test-requirements.yml b/ansible/roles/kolla-ansible/tests/test-requirements.yml new file mode 100644 index 000000000..a6063a07d --- /dev/null +++ b/ansible/roles/kolla-ansible/tests/test-requirements.yml @@ -0,0 +1,59 @@ +--- +- hosts: localhost + connection: local + tasks: + - name: Create a temporary directory + tempfile: + state: directory + register: tempfile_result + + - block: + - name: Test the kolla-ansible role with extra Python requirements + include_role: + name: ../../kolla-ansible + vars: + kolla_ansible_source_path: "{{ temp_path }}/src" + kolla_ansible_ctl_install_type: "source" + kolla_ansible_source_url: "http://github.com/openstack/kolla-ansible" + kolla_ansible_source_version: "master" + kolla_ansible_venv: "{{ temp_path }}/venv" + kolla_ansible_venv_extra_requirements: + - "hvac" + kolla_config_path: "{{ temp_path }}/etc/kolla" + kolla_node_custom_config_path: "{{ temp_path }}/etc/kolla/config" + kolla_ansible_passwords_path: "{{ temp_path }}/passwords.yml" + # Required config. + kolla_base_distro: "fake-distro" + kolla_install_type: "fake-install-type" + kolla_docker_namespace: "fake-namespace" + kolla_openstack_release: "fake-release" + kolla_internal_vip_address: "10.0.0.1" + kolla_internal_fqdn: "fake.internal.fqdn" + kolla_external_vip_address: "10.0.0.2" + kolla_external_fqdn: "fake.external.fqdn" + kolla_enable_tls_external: False + kolla_enable_grafana: False + kolla_external_fqdn_cert: "fake-cert" + kolla_openstack_logging_debug: False + + - name: List Python packages installed in virtualenv + command: "{{ temp_path }}/venv/bin/pip list" + register: kolla_ansible_venv_pip_list + changed_when: False + + - name: Verify extra requirements are installed in virtualenv + assert: + that: + - "'hvac' in kolla_ansible_venv_pip_list.stdout" + + always: + - name: Ensure the temporary directory is removed + file: + path: "{{ temp_path }}" + state: absent + rescue: + - name: Flag that a failure occurred + set_fact: + test_failures: "{{ test_failures | default(0) | int + 1 }}" + vars: + temp_path: "{{ tempfile_result.path }}" diff --git a/doc/source/configuration/kolla-ansible.rst b/doc/source/configuration/kolla-ansible.rst index 00aa627dd..8106ca29a 100644 --- a/doc/source/configuration/kolla-ansible.rst +++ b/doc/source/configuration/kolla-ansible.rst @@ -27,6 +27,22 @@ kolla-ansible is installed and executed. the kolla-ansible virtualenv will be created. ====================== ================================================== ============================ +Extra Python packages can be installed inside the kolla-ansible virtualenv, +such as when required by Ansible plugins, using the +``kolla_ansible_venv_extra_requirements`` list variable in +``$KAYOBE_CONFIG_PATH/kolla.yml``. For example, to use the `hashi_vault Ansible +lookup plugin +`_, its +``hvac`` dependency can be installed using: + +.. code-block:: yaml + :caption: ``$KAYOBE_CONFIG_PATH/kolla.yml`` + + --- + # Extra requirements to install inside the kolla-ansible virtualenv. + kolla_ansible_venv_extra_requirements: + - "hvac" + Remote Execution Environment ============================ diff --git a/etc/kayobe/kolla.yml b/etc/kayobe/kolla.yml index f89aca1e9..1a3e29e74 100644 --- a/etc/kayobe/kolla.yml +++ b/etc/kayobe/kolla.yml @@ -42,6 +42,9 @@ # Path to virtualenv in which to install kolla-ansible. #kolla_ansible_venv: +# Extra requirements to install inside the kolla-ansible virtualenv. +#kolla_ansible_venv_extra_requirements: + # Path to Kolla-ansible configuration directory. #kolla_config_path: diff --git a/releasenotes/notes/add-kolla_ansible_venv_extra_requirements-4d4f70b024207ffb.yaml b/releasenotes/notes/add-kolla_ansible_venv_extra_requirements-4d4f70b024207ffb.yaml new file mode 100644 index 000000000..4e4b435bf --- /dev/null +++ b/releasenotes/notes/add-kolla_ansible_venv_extra_requirements-4d4f70b024207ffb.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + Adds support for installing extra Python packages inside the kolla-ansible + virtualenv, such as when required by Ansible plugins. A list of extra + requirements can be configured via the + ``kolla_ansible_venv_extra_requirements`` variable in + ``$KAYOBE_CONFIG_PATH/kolla.yml``. No extra packages are installed by + default.