Installing python dependencies

The vmware_category_facts module requires the vsphere-automation-sdk for python from https://github.com/vmware/vsphere-automation-sdk-python

A straight up pip install using the pip module and git didn’t seem to work. I wound up having to install all the sub modules using a pip task that targeted them by direct url:

tasks:

Is there a better way to do this? It seems less than perfect.

Mike

Mike,

Your best option is most likely using a custom virtual environment for your playbook, or alternately adding these modules to the default virtual environment. The below link is comprehensive for setting them up, but the caveat is you now have to manage custom AWX images via Docker.

https://github.com/ansible/awx/blob/devel/docs/custom_virtualenvs.md

Here’s an example Jinja2 Dockerfile that I use that’s fed into an Ansible playbook. It references requirements.txt files managed by the tenant teams that want their own venvs. We also install Mitogen as a strategy plugin, so if you don’t need/want that you can ignore those lines.

`

FROM ansible/awx_task:{{ awx_version }}

USER root
ADD . /tmp
RUN yum install -y gcc python-devel
RUN update-ca-trust

RUN /var/lib/awx/venv/ansible/bin/pip install -q psutil python-memcached mitogen
RUN cp /tmp/playbook/build_image/files/mitogen_plugins/* /usr/lib/python2.7/site-packages/ansible/plugins/strategy

{% for venv_name in venv_list %}
RUN virtualenv /var/lib/awx/venv/{{ venv_name }} \
 && /var/lib/awx/venv/{{ venv_name }}/bin/pip install -q -r /tmp/custom_venvs/{{ venv_name }}-requirements.txt \
 && /var/lib/awx/venv/{{ venv_name }}/bin/pip install -q psutil python-memcached mitogen
RUN cp /tmp/playbook/build_image/files/mitogen_plugins/* /var/lib/awx/venv/{{ venv_name }}/lib/python2.7/site-packages/ansible/plugins/strategy
{% endfor %}

RUN yum remove -y gcc python-devel && yum clean all

`