Make local kolla-ansible Python executable configurable

The default is still Python 2. This is a necessary prerequisite for using
the master branch of kolla-ansible, which requires Python 3.

Change-Id: Ida5b60b723c8208bb7305c3d669eafdab6dbbe01
Story: 2004959
Task: 38767
This commit is contained in:
Mark Goddard 2020-01-30 12:41:26 +00:00
parent 030ede06e8
commit 6b47717c43
5 changed files with 47 additions and 8 deletions

View File

@ -15,6 +15,14 @@ kolla_ansible_source_version:
# Virtualenv directory where Kolla-ansible will be installed.
kolla_ansible_venv: "{{ ansible_env['PWD'] }}/kolla-venv"
# Python interpreter to use to create Kolla Ansible virtualenv.
# FIXME(mgoddard): Use ansible_python when Kayobe supports Python 3.
kolla_ansible_venv_python: "python{{ kolla_ansible_venv_python_major_version }}"
# Major version of Python interpreter used in Kolla Ansible virtualenv.
# FIXME(mgoddard): Use ansible_python when Kayobe supports Python 3.
kolla_ansible_venv_python_major_version: 2
# Virtualenv directory where Kolla-ansible's ansible modules will execute
# remotely on the target nodes. If None, no virtualenv will be used.
kolla_ansible_target_venv:

View File

@ -13,7 +13,8 @@
- name: Ensure required packages are installed
package:
name: "{{ kolla_ansible_package_dependencies }}"
# NOTE(mgoddard): select non-empty packages.
name: "{{ kolla_ansible_package_dependencies | select | list }}"
state: present
become: True
@ -42,11 +43,29 @@
become: True
when: kolla_ansible_venv is not none
# TODO(mgoddard): Remove this block when the previous release does not support
# Python 2.
- block:
- name: Check if virtualenv is python 2
stat:
path: "{{ kolla_ansible_venv }}/bin/python2"
register: stat_result
- name: Ensure python2 virtualenv is absent
file:
path: "{{ kolla_ansible_venv }}"
state: absent
when: stat_result.stat.exists
when:
- kolla_ansible_venv is not none
- kolla_ansible_venv_python_major_version | int == 3
- name: Ensure the latest version of pip is installed
pip:
name: "{{ item.name }}"
state: latest
virtualenv: "{{ kolla_ansible_venv }}"
virtualenv_python: "{{ kolla_ansible_venv_python }}"
with_items:
- { name: pip }
@ -65,7 +84,9 @@
# This is a workaround for the lack of a python package for libselinux-python
# on PyPI. Without using --system-site-packages to create the virtualenv, it
# seems difficult to ensure the selinux python module is available. It is a
# dependency for Ansible when selinux is enabled.
# dependency for Ansible when selinux is enabled. On CentOS 8, we can install
# the selinux package from PyPI, however when using Python 3 on CentOS 7 this
# does not work.
- name: Ensure selinux Python package is linked into the virtualenv
file:
src: "/usr/lib64/python2.7/site-packages/selinux"
@ -75,3 +96,4 @@
- ansible_os_family == 'RedHat'
- ansible_selinux != False
- ansible_selinux.status != 'disabled'
- kolla_ansible_venv_python_major_version | int == 2

View File

@ -4,6 +4,15 @@
# Components define groups of services, e.g. nova or ironic.
# Services define single containers, e.g. nova-compute or ironic-api.
{% if ansible_os_family == 'RedHat' and ansible_distribution_major_version | int == 7 and kolla_ansible_venv_python_major_version | int == 3 %}
# TODO(mgoddard): Remove when CentOS 7 is no longer supported.
# Force the use of python2 for localhost. This is necessary for delegate_to:
# localhost, which will otherwise use the playbook python interpreter
# (python3). On CentOS 7, that fails due to a lack of python3 bindings for
# SELinux. https://bugs.centos.org/view.php?id=16389
localhost ansible_python_interpreter=/usr/bin/python2
{% endif %}
{% for group in kolla_overcloud_top_level_groups %}
# Top level {{ group }} group.
[{{ group }}]

View File

@ -5,6 +5,6 @@ kolla_ansible_package_dependencies:
- libffi-dev
- libssl-dev
- patch
- python-dev
- python-pip
- python-virtualenv
- "python{% if kolla_ansible_venv_python_major_version | int == 3 %}3{% endif %}-dev"
- "python{% if kolla_ansible_venv_python_major_version | int == 3 %}3{% endif %}-pip"
- "python{% if kolla_ansible_venv_python_major_version | int == 3 %}3-venv{% else %}-virtualenv{% endif %}"

View File

@ -5,6 +5,6 @@ kolla_ansible_package_dependencies:
- libffi-devel
- openssl-devel
- patch
- python-devel
- python-pip
- python-virtualenv
- "python{% if kolla_ansible_venv_python_major_version | int == 3 %}3{% endif %}-devel"
- "python{% if kolla_ansible_venv_python_major_version | int == 3 %}3{% endif %}-pip"
- "{% if kolla_ansible_venv_python_major_version | int == 2 %}python-virtualenv{% endif %}"