Move ansible to virtualenv in kolla_toolbox

Now the ansible and its python dependencies are installed on system. It
may be failed to install in some case. This patch installs python
packages in virtualenv for kolla_toolbox image.

Closes-Bug: #1771717
Change-Id: I3c4465d5dfe4f909521fa00173f1cf8d9eec783f
(cherry picked from commit ce31fa4b1c)
This commit is contained in:
Jeffrey Zhang 2018-04-02 09:09:24 +08:00 committed by Jeffrey Zhang
parent 9f4f55b179
commit 42ffb140df

View File

@ -3,7 +3,8 @@ LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build
{% block kolla_toolbox_header %}{% endblock %}
{% set os_client_config='/usr/lib/python2.7/site-packages/os_client_config/defaults.json' %}
{% set virtualenv_path='/opt/ansible' %}
{% set os_client_config= virtualenv_path + '/lib/python2.7/site-packages/os_client_config/defaults.json' %}
{% import "macros.j2" as macros with context %}
@ -83,6 +84,15 @@ RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \
&& rm get-pip.py
{% endblock %}
{% set kolla_toolbox_pip_virtualenv_packages = [
'virtualenv'
] %}
RUN {{ macros.install_pip(kolla_toolbox_pip_virtualenv_packages|customizable("pip_packages"), constraints=false) }} \
&& virtualenv --system-site-packages {{ virtualenv_path }}
ENV PATH {{ virtualenv_path }}/bin:$PATH
{% set kolla_toolbox_pip_packages = [
'ansible==2.2.0.0',
'"cmd2<0.9.0"',
@ -96,12 +106,13 @@ RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \
'shade==1.16.0'
] %}
RUN {{ macros.install_pip(kolla_toolbox_pip_packages | customizable("pip_packages"), constraints = false) }}
RUN mkdir -p /etc/ansible /usr/share/ansible \
&& echo 'localhost ansible_connection=local' > /etc/ansible/hosts \
RUN {{ macros.install_pip(kolla_toolbox_pip_packages | customizable("pip_packages"), constraints=false) }} \
&& mkdir -p /etc/ansible /usr/share/ansible \
&& echo 'localhost ansible_connection=local ansible_python_interpreter={{ virtualenv_path }}/bin/python' > /etc/ansible/hosts \
&& sed -i 's| "identity_api_version": "2.0",| "identity_api_version": "3",|' {{ os_client_config }}
ENV ANSIBLE_LIBRARY /usr/share/ansible:$ANSIBLE_LIBRARY
COPY find_disks.py kolla_keystone_service.py kolla_keystone_user.py kolla_sanity.py /usr/share/ansible/
COPY ansible.cfg /var/lib/ansible/.ansible.cfg