Skip to content
Snippets Groups Projects
kolla-target-venv.yml 2.67 KiB
Newer Older
---
# Create a virtualenv for ansible modules to use on the remote target systems
# when running kolla-ansible.

- name: Ensure a virtualenv exists for kolla-ansible
  vars:
    # kolla_overcloud_inventory_top_level_group_map looks like:
    # kolla_overcloud_inventory_top_level_group_map:
    #  control:
    #    groups:
    #      - controllers
    hosts_in_kolla_inventory: >-
      {{ kolla_overcloud_inventory_top_level_group_map.values() |
         map(attribute='groups') | flatten | unique | union(['seed']) | join(':') }}
  tags:
    - kolla-ansible
    - kolla-target-venv
  tasks:
    - block:
        - name: Gather facts
          setup:
          when: not module_setup | default(false)

        - name: Ensure the Python virtualenv package is installed
            name: python{{ ansible_python.version.major }}-virtualenv
            state: present
          become: True

        - name: Ensure kolla-ansible virtualenv has the latest version of pip installed
          pip:
            name: pip
            state: latest
            virtualenv: "{{ kolla_ansible_target_venv }}"
            # Site packages are required for using the yum and selinux python
            # modules, which are not available via PyPI.
            virtualenv_site_packages: True
            virtualenv_python: "python{{ ansible_python.version.major }}.{{ ansible_python.version.minor }}"
          become: True

        - name: Ensure kolla-ansible virtualenv has docker SDK for python installed
          pip:
            name: docker
            state: latest
            virtualenv: "{{ kolla_ansible_target_venv }}"
            extra_args: "{% if kolla_upper_constraints_file %}-c {{ kolla_upper_constraints_file }}{% endif %}"
        # NOTE(mgoddard): SELinux python bindings available on PyPI only work
        # with Python 3 on CentOS 8.
        - name: Ensure kolla-ansible virtualenv has SELinux bindings installed
          pip:
            name: selinux
            state: latest
            virtualenv: "{{ kolla_ansible_target_venv }}"
          become: True
          when:
            - ansible_os_family == 'RedHat'
            - ansible_distribution_major_version | int >= 8

        - name: Ensure kolla-ansible virtualenv has correct ownership
          file:
            path: "{{ kolla_ansible_target_venv }}"
            recurse: True
            state: directory
            owner: "{{ kolla_ansible_user }}"
            group: "{{ kolla_ansible_group }}"
      when:
        - kolla_ansible_target_venv is not none
        - inventory_hostname in query('inventory_hostnames', hosts_in_kolla_inventory)