kayobe/ansible/kayobe-target-venv.yml
Piotr Parczewski 6ee7333e7e Fix Python setup when venv is not used
Set packages argument explicitly as a list to avoid "No package matching
'<generator object select_or_reject at 0x7ff25f341750>' is available" error.

Story: 2008378
Task: 41298
Change-Id: Ibe44583cb93b7dca8f5091c893386a15288af915
(cherry picked from commit e748faea00)
2021-01-13 11:35:08 +00:00

96 lines
3.2 KiB
YAML

---
# Create a virtualenv for ansible modules to use on the remote target systems
# when running kayobe.
- name: Ensure a virtualenv exists for kayobe
hosts: seed:seed-hypervisor:overcloud
gather_facts: False
tags:
- kayobe-target-venv
tasks:
- name: Set a fact about the kayobe target virtualenv
set_fact:
virtualenv: "{{ ansible_python_interpreter | dirname | dirname }}"
when:
- ansible_python_interpreter is defined
- not ansible_python_interpreter.startswith('/bin')
- not ansible_python_interpreter.startswith('/usr/bin')
- block:
- name: Gather facts
setup:
when: not module_setup | default(false)
register: gather_facts
- name: Ensure the Python virtualenv package is installed
package:
name: python3-virtualenv
state: present
become: True
- name: Ensure global virtualenv directory exists
file:
path: "{{ virtualenv_path }}"
state: directory
owner: "{{ ansible_user_uid }}"
group: "{{ ansible_user_gid }}"
mode: 0755
# Check whether the virtualenv directory is a subdirectory of the
# global virtualenv directory.
when: virtualenv.startswith(virtualenv_path)
become: True
- name: Ensure kayobe virtualenv directory exists
file:
path: "{{ virtualenv }}"
state: directory
owner: "{{ ansible_user_uid }}"
group: "{{ ansible_user_gid }}"
mode: 0700
become: True
- name: Ensure kayobe virtualenv has the latest version of pip installed
pip:
name: pip
state: latest
virtualenv: "{{ virtualenv }}"
# Site packages are required for using the dnf module, which is not
# available via PyPI.
virtualenv_site_packages: True
virtualenv_python: "python3.{{ ansible_python.version.minor }}"
- name: Ensure kayobe virtualenv has SELinux bindings installed
pip:
name: selinux
state: latest
virtualenv: "{{ virtualenv }}"
when:
- ansible_os_family == 'RedHat'
vars:
# Use the system python interpreter since the virtualenv might not
# exist.
ansible_python_interpreter: /usr/libexec/platform-python
when: virtualenv is defined
# If we gathered facts earlier it would have been with a different Python
# interpreter. For gathering modes that may use a fact cache, gather facts
# again using the interpreter from the virtual environment.
- name: Gather facts
setup:
when:
- virtualenv is defined
- gather_facts is not skipped
- lookup('config', 'DEFAULT_GATHERING') != 'implicit'
- block:
- name: Ensure Python setuptools and pip packages are installed
vars:
packages:
- python3-setuptools
- python3-pip
package:
name: "{{ packages | select | list }}"
state: present
become: True
when: virtualenv is not defined