Migrate pip_install.yml to a new role bifrost-pip-install

Allows de-duplicating pip_install.yml between ironic and keystone,
fixes numerous inconsistencies and centralizes venv and skip_install
handling.

Change-Id: Id6a1a4f3ebe2010ab14f43a306b084f4525d5862
This commit is contained in:
Dmitry Tantsur 2020-06-14 12:59:59 +02:00
parent 2dab2f5ad9
commit 2c9ede32c9
12 changed files with 243 additions and 329 deletions

View File

@ -20,25 +20,14 @@
venv_command: "python3 -m venv"
when: enable_venv
- name: install libvirt-python and lxml without virtualenv
pip:
name: "{{ item }}"
extra_args: "-c {{ upper_constraints_file }}"
- name: install libvirt-python and lxml
include_role:
name: bifrost-pip-install
vars:
package: "{{ item }}"
loop:
- libvirt-python
- lxml
when: enable_venv | bool == false
- name: install libvirt-python and lxml with virtualenv
pip:
name: "{{ item }}"
state: present
virtualenv: "{{ bifrost_venv_dir }}"
virtualenv_command: "{{ venv_command | default(omit) }}"
loop:
- libvirt-python
- lxml
when: enable_venv | default(false) | bool
- name: configure libvirt log filters for qemu
blockinfile:
@ -169,11 +158,10 @@
mode: "0755"
- name: install virtualbmc
pip:
name: virtualbmc
extra_args: "-c {{ upper_constraints_file }}"
virtualenv: "{{ enable_venv | bool | ternary(bifrost_venv_dir, omit) }}"
become: true
include_role:
name: bifrost-pip-install
vars:
package: virtualbmc
- name: ensure Virtual BMC systemd service is configured
template:

View File

@ -116,7 +116,6 @@ ironicclient_git_folder: /opt/stack/python-ironicclient
openstacksdk_git_folder: /opt/stack/openstacksdk
dib_git_folder: /opt/stack/diskimage-builder
reqs_git_folder: /opt/stack/requirements
upper_constraints_file: "{{ lookup('env', 'UPPER_CONSTRAINTS_FILE') | default(reqs_git_folder + '/upper-constraints.txt', True) }}"
staging_drivers_git_folder: /opt/stack/ironic-staging-drivers
ironicinspector_git_folder: /opt/stack/ironic-inspector
ironicinspectorclient_git_folder: /opt/stack/python-ironic-inspector-client

View File

@ -13,18 +13,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: "Inspector - PIP Install"
include: pip_install.yml
package=ironic-inspector
state=latest
sourcedir={{ ironicinspector_git_folder }}
source_install={{ ironicinspector_source_install }}
extra_args="--no-cache-dir {{ pip_opts }}"
- name: "Inspector - install"
include_role:
name: bifrost-pip-install
vars:
package: ironic-inspector
sourcedir: "{{ ironicinspector_git_folder }}"
source_install: "{{ ironicinspector_source_install }}"
extra_args: "--no-cache-dir {{ pip_opts }}"
- name: "Inspector - PIP client install"
include: pip_install.yml
package=python-ironic-inspector-client
state=latest
sourcedir={{ ironicinspectorclient_git_folder }}
source_install={{ ironicinspectorclient_source_install }}
extra_args="--no-cache-dir {{ pip_opts }}"
- name: "Inspector - client install"
include_role:
name: bifrost-pip-install
vars:
package: python-ironic-inspector-client
sourcedir: "{{ ironicinspectorclient_git_folder }}"
source_install: "{{ ironicinspectorclient_source_install }}"
extra_args: "--no-cache-dir {{ pip_opts }}"

View File

@ -38,11 +38,10 @@
file: name=/opt/stack state=directory owner=root group=root
- name: "proliantutils - Install from pip"
include: pip_install.yml
package=proliantutils
state=present
environment: "{{ venv }}"
when: skip_install is not defined
include_role:
name: bifrost-pip-install
vars:
package: proliantutils
- name: "Install iSCSI client and dependencies if iscsi deploy interface is enabled"
package:
@ -51,91 +50,84 @@
when: skip_install is not defined and 'iscsi' in enabled_deploy_interfaces
- name: "IPA-builder - Install"
include: pip_install.yml
package=ironic-python-agent-builder
sourcedir={{ ipa_builder_git_folder }}
source_install=true
when: skip_install is not defined and install_dib | bool == true
include_role:
name: bifrost-pip-install
vars:
package: ironic-python-agent-builder
sourcedir: "{{ ipa_builder_git_folder }}"
source_install: true
when: install_dib | bool == true
# NOTE(mgoddard): IPA-builder has a dependency on diskimage-builder. Install
# DIB last to ensure it is installed from source rather than PyPI.
- name: "Diskimage-builder - Install"
include: pip_install.yml
package=diskimage-builder
sourcedir={{ dib_git_folder }}
source_install=true
when: skip_install is not defined and install_dib | bool == true
include_role:
name: bifrost-pip-install
vars:
package: diskimage-builder
sourcedir: "{{ dib_git_folder }}"
source_install: true
when: install_dib | bool == true
- name: "sushy - Install"
include: pip_install.yml
package=sushy
sourcedir={{ sushy_git_folder }}
source_install={{ sushy_source_install }}
when: skip_install is not defined
include_role:
name: bifrost-pip-install
vars:
package: sushy
sourcedir: "{{ sushy_git_folder }}"
source_install: "{{ sushy_source_install }}"
- name: "Ironic Client - Install"
include: pip_install.yml
package=python-ironicclient
state=latest
sourcedir={{ ironicclient_git_folder }}
source_install={{ ironicclient_source_install }}
when: skip_install is not defined
include_role:
name: bifrost-pip-install
vars:
package: python-ironicclient
sourcedir: "{{ ironicclient_git_folder }}"
source_install: "{{ ironicclient_source_install }}"
# NOTE(dtantsur): no much value in installing metalsmith from source - it does
# not change often, and nothing in bifrost depends on it.
- name: "metalsmith - Install"
include: pip_install.yml
package=metalsmith
state=latest
when: skip_install is not defined
include_role:
name: bifrost-pip-install
vars:
package: metalsmith
source_install: false
- name: "Install configparser in venv if using"
include: pip_install.yml
package=configparser
virtualenv={{ bifrost_venv_dir }}
when: skip_install is not defined and (enable_venv | bool == true)
- name: "Install pymysql in venv if using"
include: pip_install.yml
package=pymysql
state=latest
virtualenv={{ bifrost_venv_dir }}
when:
- skip_install is not defined
- enable_venv | bool == true
- name: "Install pymysql for non-venv environments to support Ansible"
include: pip_install.yml
package=pymysql
when:
- skip_install is not defined
- enable_venv | bool == false
- name: "Install pymysql"
include_role:
name: bifrost-pip-install
vars:
package: pymysql
- name: "Install extra packages for ironic"
include: pip_install.yml
package={{ item }}
include_role:
name: bifrost-pip-install
vars:
package: "{{ item }}"
loop: "{{ ironic_extra_packages }}"
- name: "Install Ironic using pip"
include: pip_install.yml
package=ironic
state=latest
sourcedir={{ ironic_git_folder }}
source_install=true
extra_args="--no-cache-dir {{ pip_opts }}"
when: skip_install is not defined
include_role:
name: bifrost-pip-install
vars:
package: ironic
sourcedir: "{{ ironic_git_folder }}"
source_install: true
extra_args: "--no-cache-dir {{ pip_opts }}"
- name: "Install ironic-inspector to permit use of inspection interface"
include: inspector_install.yml
when: skip_install is not defined and enable_inspector | bool == true
include_tasks: inspector_install.yml
when: enable_inspector | bool == true
- name: "Install ironic-staging-drivers"
include: staging_install.yml
when: skip_install is not defined and staging_drivers_include | bool == true
include_tasks: staging_install.yml
when: staging_drivers_include | bool == true
- name: install openstacksdk
include: pip_install.yml
package=openstacksdk
sourcedir={{ openstacksdk_git_folder }}
source_install={{ openstacksdk_source_install }}
when: skip_install is not defined
- name: "Install openstacksdk"
include_role:
name: bifrost-pip-install
vars:
package: openstacksdk
sourcedir: "{{ openstacksdk_git_folder }}"
source_install: "{{ openstacksdk_source_install }}"

View File

@ -1,71 +0,0 @@
# Copyright (c) 2015 Hewlett Packard Enterprise Development LP.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: Set extra_args if upper_constraints_file is defined
set_fact:
constraints_extra_args: "{{ extra_args | default('') }} -c {{ upper_constraints_file }}"
when:
- (upper_constraints_file | default('')) != ''
# NOTE(dtantsur): constraining does not work correctly correctly with
# source installation if the package itself is in constraints.
- source_install is not defined or source_install == false
- name: "Install {{ package }} package from pip using virtualenv"
pip:
name: "{{ package }}"
state: "{{ state | default(omit) }}"
version: "{{ version | default(omit) }}"
virtualenv: "{{ bifrost_venv_dir }}"
virtualenv_command: "python3 -m venv"
extra_args: "{{ constraints_extra_args | default(extra_args) | default(omit) }}"
requirements: "{{ requirements_file | default(omit) }}"
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: 5
delay: 10
when: (source_install is not defined or source_install | bool == false ) and enable_venv | bool
- name: "Install {{ package }} package from pip without virtualenv"
pip:
name: "{{ package }}"
state: "{{ state | default(omit) }}"
version: "{{ version | default(omit) }}"
extra_args: "{{ constraints_extra_args | default(extra_args) | default(omit) }}"
requirements: "{{ requirements_file | default(omit) }}"
executable: /usr/bin/pip3
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: 5
delay: 10
when: (source_install is not defined or source_install | bool == false ) and enable_venv | bool == false
- name: "Install requirements from {{ sourcedir }} using pip"
pip:
extra_args: "{{ extra_args | default('') }} {% if upper_constraints_file %}-c {{ upper_constraints_file }}{% endif %}"
requirements: "{{ sourcedir }}/requirements.txt"
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: 5
delay: 10
when: source_install is defined and source_install | default(true) | bool
environment: "{{ bifrost_venv_env if (enable_venv | bool) else {} }}"
# NOTE(dtantsur): do not use constraints here, it does not work when the
# package itself is constrained.
- name: "Install from {{ sourcedir }} using pip"
command: pip3 install {{ sourcedir }} {{ extra_args | default('') }}
when: source_install is defined and (source_install | bool == true)
environment: "{{ bifrost_venv_env if (enable_venv | bool) else {} }}"

View File

@ -14,9 +14,10 @@
# limitations under the License.
---
- name: "Ironic-staging-drivers - PIP Install"
include: pip_install.yml
package=ironic-staging-drivers
state=latest
sourcedir={{ staging_drivers_git_folder }}
source_install={{ staging_drivers_source_install }}
extra_args="--no-cache-dir --upgrade-strategy only-if-needed"
include_role:
name: bifrost-pip-install
vars:
package: ironic-staging-drivers
sourcedir: "{{ staging_drivers_git_folder }}"
source_install: "{{ staging_drivers_source_install }}"
extra_args: "--no-cache-dir --upgrade-strategy only-if-needed"

View File

@ -27,81 +27,29 @@
file: name=/opt/stack state=directory owner=root group=root
when: skip_install is not defined
# NOTE(TheJulia): Part of Bifrost's install does this as well, but
# duplicating here as we are installing a separate service with this.
# We may wish to refactor this at a later point in time.
- name: "Install configparser in venv if using"
include: pip_install.yml
package=configparser
virtualenv=bifrost_venv_dir
when:
- skip_install is not defined
- enable_venv | bool == true
- name: "Install pymysql in venv if using"
include: pip_install.yml
package=pymysql
virtualenv=bifrost_venv_dir
when:
- skip_install is not defined
- enable_venv | bool == true
- name: "Install pymysql"
include_role:
name: bifrost-pip-install
vars:
package: pymysql
- name: "Install uWSGI in venv if using"
include: pip_install.yml
package=uWSGI
virtualenv=bifrost_venv_dir
when:
- skip_install is not defined
- enable_venv | bool == true
include_role:
name: bifrost-pip-install
vars:
package: uWSGI
- name: "Install python-openstackclient in venv if using"
include: pip_install.yml
package=python-openstackclient
virtualenv=bifrost_venv_dir
when:
- skip_install is not defined
- enable_venv | bool == true
- name: "Install python-openstackclient"
include_role:
name: bifrost-pip-install
vars:
package: python-openstackclient
- name: "Install keystone in venv if using"
include: pip_install.yml
package=keystone
virtualenv=bifrost_venv_dir
state=latest
sourcedir={{ keystone_git_folder }}
source_install={{ keystone_source_install | bool }}
extra_args="--no-cache-dir {{ pip_opts }}"
when:
- skip_install is not defined
- enable_venv | bool == true
- name: "Install configparser if not using a venv"
include: pip_install.yml
package=configparser
when:
- skip_install is not defined
- enable_venv | bool == false
- name: "Install pymysql if not using a venv"
include: pip_install.yml
package=pymysql
when:
- skip_install is not defined
- enable_venv | bool == false
- name: "Install python-openstackclient if not using a venv"
include: pip_install.yml
package=python-openstackclient
when:
- skip_install is not defined
- enable_venv | bool == false
- name: "Install keystone if not using a venv"
include: pip_install.yml
package=keystone
state=latest
sourcedir={{ keystone_git_folder }}
source_install={{ keystone_source_install | bool }}
extra_args="--no-cache-dir {{ pip_opts }}"
when:
- skip_install is not defined
- enable_venv | bool == false
- name: "Install keystone"
include_role:
name: bifrost-pip-install
vars:
package: keystone
sourcedir: "{{ keystone_git_folder }}"
source_install: "{{ keystone_source_install }}"
extra_args: "--no-cache-dir {{ pip_opts }}"

View File

@ -1,71 +0,0 @@
# Copyright (c) 2015 Hewlett Packard Enterprise Development LP.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: Set extra_args if upper_constraints_file is defined
set_fact:
constraints_extra_args: "{{ extra_args | default('') }} -c {{ upper_constraints_file }}"
when:
- (upper_constraints_file | default('')) != ''
# NOTE(dtantsur): constraining does not work correctly correctly with
# source installation if the package itself is in constraints.
- source_install is not defined or source_install == false
- name: "Install {{ package }} package from pip using virtualenv"
pip:
name: "{{ package }}"
state: "{{ state | default(omit) }}"
version: "{{ version | default(omit) }}"
virtualenv: "{{ bifrost_venv_dir }}"
virtualenv_command: "python3 -m venv"
extra_args: "{{ constraints_extra_args | default(extra_args) | default(omit) }}"
requirements: "{{ requirements_file | default(omit) }}"
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: 5
delay: 10
when: (source_install is not defined or source_install | bool == false ) and enable_venv | bool
- name: "Install {{ package }} package from pip without virtualenv"
pip:
name: "{{ package }}"
state: "{{ state | default(omit) }}"
version: "{{ version | default(omit) }}"
extra_args: "{{ constraints_extra_args | default(extra_args) | default(omit) }}"
requirements: "{{ requirements_file | default(omit) }}"
executable: /usr/bin/pip3
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: 5
delay: 10
when: (source_install is not defined or source_install | bool == false ) and enable_venv | bool == false
- name: "Install requirements from {{ sourcedir }} using pip"
pip:
extra_args: "{{ extra_args | default('') }} {% if upper_constraints_file %}-c {{ upper_constraints_file }}{% endif %}"
requirements: "{{ sourcedir }}/requirements.txt"
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: 5
delay: 10
when: source_install is defined and source_install | default(true) | bool
environment: "{{ bifrost_venv_env if (enable_venv | bool) else {} }}"
# NOTE(dtantsur): do not use constraints here, it does not work when the
# package itself is constrained.
- name: "Install from {{ sourcedir }} using pip"
command: pip3 install {{ sourcedir }} {{ extra_args | default('') }}
when: source_install is defined and (source_install | bool == true)
environment: "{{ bifrost_venv_env if (enable_venv | bool) else {} }}"

View File

@ -0,0 +1,32 @@
bifrost-pip-install
===================
This role installs packages from PIP or source depending on configuration
and applies upper constraints if provided.
Requirements
------------
This role requires:
- Ansible 2.9
License
-------
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author Information
------------------
Ironic Developers

View File

@ -0,0 +1,17 @@
---
# Global options
bifrost_venv_dir: "{{ lookup('env', 'VENV') | default('/opt/stack/bifrost') }}"
bifrost_venv_env:
VIRTUAL_ENV: "{{ bifrost_venv_dir }}"
PATH: "{{ bifrost_venv_dir }}/bin:{{ ansible_env.PATH }}" # include regular path via lookup env
enable_venv: true
source_install: false
# Pip options
extra_args:
pip_install_retries: 5
pip_install_delay: 10
reqs_git_folder: /opt/stack/requirements
state: present
version:
upper_constraints_file: "{{ lookup('env', 'UPPER_CONSTRAINTS_FILE') | default(reqs_git_folder + '/upper-constraints.txt', True) }}"

View File

@ -0,0 +1,78 @@
# Copyright (c) 2015 Hewlett Packard Enterprise Development LP.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- block:
- name: "Check that sourcedir is provided with source_install"
fail:
msg: Source installation of requires sourcedir to be provided
when: source_install | bool and sourcedir | default('') == ''
- name: "Set extra_args if upper_constraints_file is defined"
set_fact:
constraints_extra_args: "{{ extra_args | default('') }} -c {{ upper_constraints_file }}"
when:
- upper_constraints_file != ''
# NOTE(dtantsur): constraining does not work correctly correctly with
# source installation if the package itself is in constraints.
- source_install | bool == false
- name: "Install {{ package }} package from pip using virtualenv"
pip:
name: "{{ package }}"
state: "{{ state | default(omit) }}"
version: "{{ version | default(omit) }}"
virtualenv: "{{ bifrost_venv_dir }}"
virtualenv_command: "python3 -m venv"
extra_args: "{{ constraints_extra_args | default(extra_args) | default(omit) }}"
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: "{{ pip_install_retries }}"
delay: "{{ pip_install_delay }}"
when: source_install | bool == false and enable_venv | bool
- name: "Install {{ package }} package from pip without virtualenv"
pip:
name: "{{ package }}"
state: "{{ state | default(omit) }}"
version: "{{ version | default(omit) }}"
extra_args: "{{ constraints_extra_args | default(extra_args) | default(omit) }}"
executable: /usr/bin/pip3
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: "{{ pip_install_retries }}"
delay: "{{ pip_install_delay }}"
when: source_install | bool == false and enable_venv | bool == false
- name: "Install requirements from {{ sourcedir }} using pip"
pip:
extra_args: "{{ extra_args | default('') }} {% if upper_constraints_file %}-c {{ upper_constraints_file }}{% endif %}"
requirements: "{{ sourcedir }}/requirements.txt"
register: pip_package_install_done
until: pip_package_install_done is succeeded
retries: 5
delay: 10
when: source_install | bool
environment: "{{ bifrost_venv_env if (enable_venv | bool) else {} }}"
# NOTE(dtantsur): do not use constraints here, it does not work when the
# package itself is constrained.
- name: "Install from {{ sourcedir }} using pip"
command: pip3 install {{ sourcedir }} {{ extra_args | default('') }}
when: source_install | bool
environment: "{{ bifrost_venv_env if (enable_venv | bool) else {} }}"
when: skip_install | default(false) | bool == false

View File

@ -22,7 +22,6 @@ ironicinspectorclient_git_folder: "{{ git_root}}/python-ironic-inspector-client"
openstacksdk_git_folder: "{{ git_root}}/openstacksdk"
dib_git_folder: "{{ git_root }}/diskimage-builder"
reqs_git_folder: "{{ git_root }}/requirements"
upper_constraints_file: "{{ lookup('env', 'UPPER_CONSTRAINTS_FILE') | default(reqs_git_folder + '/upper-constraints.txt', True) }}"
staging_drivers_git_folder: "{{ git_root }}/ironic-staging-drivers"
keystone_git_folder: "{{ git_root}}/keystone"
sushy_git_folder: "{{ git_root}}/sushy"