Reduce amount of task that are executed
With this patch we're trying to optimize role runtime by replacing separate tasks with loops. Hoepfully, this will slighlty improve permorfance as we need less connections now. We also create a venv with pip module rather then command. Change-Id: I219c0336079ca89bde586c8076bd964fada747c6
This commit is contained in:
parent
185713df0e
commit
26ef6bd7b8
|
@ -73,6 +73,12 @@
|
|||
tags:
|
||||
- install
|
||||
|
||||
- import_tasks: "python_venv_set_facts.yml"
|
||||
- include_tasks: "python_venv_set_facts.yml"
|
||||
args:
|
||||
apply:
|
||||
tags:
|
||||
- install
|
||||
when:
|
||||
- venv_facts_when_changed | length > 0
|
||||
tags:
|
||||
- install
|
||||
- always
|
||||
|
|
|
@ -49,17 +49,9 @@
|
|||
|
||||
- name: Create the venv_install_destination_path parent directory
|
||||
file:
|
||||
path: "{{ venv_install_destination_path | dirname }}"
|
||||
path: "{{ venv_install_destination_path }}"
|
||||
state: directory
|
||||
|
||||
- name: Create the virtualenv (if it does not exist)
|
||||
command: >-
|
||||
{{ venv_python_executable }}
|
||||
-m venv
|
||||
{{ venv_install_destination_path }}
|
||||
args:
|
||||
creates: "{{ venv_install_destination_path }}/bin/activate"
|
||||
|
||||
# Note(jrosser)
|
||||
# If the constraints file from the wheel build has been previously collected
|
||||
# then we must remove any git+... requirements from the input packages list
|
||||
|
@ -88,38 +80,33 @@
|
|||
# the conditional when installing the packages, any git constraints
|
||||
# would result in the package for that constraint always being
|
||||
# reinstalled.
|
||||
- name: Build requirements file for the venv
|
||||
- name: Build requirement and constraint files for the venv
|
||||
copy:
|
||||
dest: "{{ venv_install_destination_path }}/requirements.txt"
|
||||
content: |-
|
||||
{% for item in _venv_install_pip_packages | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
register: _requirement_file
|
||||
|
||||
- name: Build global constraints file for the venv
|
||||
copy:
|
||||
dest: "{{ venv_install_destination_path }}/global-constraints.txt"
|
||||
content: |-
|
||||
{% for item in venv_build_global_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
register: _global_constraint_file
|
||||
|
||||
- name: Build constraints file for the venv
|
||||
copy:
|
||||
dest: "{{ venv_install_destination_path }}/constraints.txt"
|
||||
content: |-
|
||||
{%- if (venv_wheel_build_enable | bool) and
|
||||
(_constraints_file_slurp is defined) and
|
||||
(_constraints_file_slurp.content is defined) %}
|
||||
{{ _constraints_file_slurp.content | b64decode }}
|
||||
{%- else %}
|
||||
{% for item in venv_build_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{%- endif %}
|
||||
register: _constraint_file
|
||||
dest: "{{ item.dest }}"
|
||||
content: "{{ item.content }}"
|
||||
with_items:
|
||||
- dest: "{{ venv_install_destination_path }}/requirements.txt"
|
||||
content: |-
|
||||
{% for item in _venv_install_pip_packages | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
- dest: "{{ venv_install_destination_path }}/global-constraints.txt"
|
||||
content: |-
|
||||
{% for item in venv_build_global_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
- dest: "{{ venv_install_destination_path }}/constraints.txt"
|
||||
content: |-
|
||||
{%- if (venv_wheel_build_enable | bool) and
|
||||
(_constraints_file_slurp is defined) and
|
||||
(_constraints_file_slurp.content is defined) %}
|
||||
{{ _constraints_file_slurp.content | b64decode }}
|
||||
{%- else %}
|
||||
{% for item in venv_build_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{%- endif %}
|
||||
register: _requirement_constraints_file
|
||||
|
||||
- name: Upgrade pip/setuptools/wheel to the versions we want
|
||||
pip:
|
||||
|
@ -128,7 +115,8 @@
|
|||
- setuptools
|
||||
- wheel
|
||||
state: "{{ venv_pip_package_state }}"
|
||||
executable: "{{ venv_install_destination_path }}/bin/pip"
|
||||
virtualenv: "{{ venv_install_destination_path }}"
|
||||
virtualenv_command: "{{ venv_python_executable }} -m venv"
|
||||
extra_args: >-
|
||||
--constraint {{ venv_install_destination_path }}/global-constraints.txt
|
||||
--constraint {{ venv_install_destination_path }}/constraints.txt
|
||||
|
@ -161,7 +149,7 @@
|
|||
{{ venv_default_pip_install_args }}
|
||||
{{ venv_pip_install_args }}
|
||||
environment: "{{ venv_pip_install_env }}"
|
||||
when: (_requirement_file is changed) or (_global_constraint_file is changed) or (_constraint_file is changed)
|
||||
when: _requirement_constraints_file.results | selectattr('changed') | length > 0
|
||||
register: _install_venv_pip_packages
|
||||
until: _install_venv_pip_packages is success
|
||||
retries: 5
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
file:
|
||||
path: /etc/ansible/facts.d
|
||||
state: directory
|
||||
when:
|
||||
- venv_facts_when_changed != []
|
||||
|
||||
- name: Record the necessary facts
|
||||
become: true
|
||||
|
@ -30,7 +28,6 @@
|
|||
value: "{{ item.value | string }}"
|
||||
with_items: "{{ venv_facts_when_changed }}"
|
||||
when:
|
||||
- venv_facts_when_changed != []
|
||||
- (_install_venv_pip_packages is defined and
|
||||
_install_venv_pip_packages is mapping and
|
||||
_install_venv_pip_packages is changed)
|
||||
|
|
|
@ -46,58 +46,38 @@
|
|||
|
||||
- name: Create wheel directory on the build host
|
||||
file:
|
||||
path: "{{ venv_build_host_wheel_path }}"
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: "{{ venv_build_host_user_name | default(omit) }}"
|
||||
group: "{{ venv_build_host_group_name | default(omit) }}"
|
||||
with_items:
|
||||
- "{{ venv_build_host_wheel_path }}"
|
||||
- "{{ venv_build_host_requirements_path }}"
|
||||
- "{{ venv_build_host_venv_path }}"
|
||||
|
||||
- name: Create requirements/constraints file directory on the build host
|
||||
file:
|
||||
path: "{{ venv_build_host_requirements_path }}"
|
||||
state: directory
|
||||
owner: "{{ venv_build_host_user_name | default(omit) }}"
|
||||
group: "{{ venv_build_host_group_name | default(omit) }}"
|
||||
|
||||
- name: Create the wheel build virtualenv (if it does not exist)
|
||||
command: >-
|
||||
{{ venv_python_executable }}
|
||||
-m venv
|
||||
{{ venv_build_host_venv_path }}
|
||||
args:
|
||||
creates: "{{ venv_build_host_venv_path }}/bin/activate"
|
||||
|
||||
- name: Build requirements file for the venv
|
||||
- name: Build requirement and constraint files for the venv
|
||||
copy:
|
||||
dest: "{{ _venv_build_requirements_prefix }}-requirements.txt"
|
||||
content: |-
|
||||
{% for item in _venv_pip_packages | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
dest: "{{ item.dest }}"
|
||||
content: "{{ item.content }}"
|
||||
owner: "{{ venv_build_host_user_name | default(omit) }}"
|
||||
group: "{{ venv_build_host_group_name | default(omit) }}"
|
||||
register: _requirement_file
|
||||
|
||||
- name: Build global constraints file for the venv
|
||||
copy:
|
||||
dest: "{{ _venv_build_requirements_prefix }}-global-constraints.txt"
|
||||
content: |-
|
||||
{% for item in venv_build_global_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
owner: "{{ venv_build_host_user_name | default(omit) }}"
|
||||
group: "{{ venv_build_host_group_name | default(omit) }}"
|
||||
register: _global_constraint_file
|
||||
|
||||
- name: Build constraints file for the venv
|
||||
copy:
|
||||
dest: "{{ _venv_build_requirements_prefix }}-source-constraints.txt"
|
||||
content: |-
|
||||
{% for item in venv_build_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
owner: "{{ venv_build_host_user_name | default(omit) }}"
|
||||
group: "{{ venv_build_host_group_name | default(omit) }}"
|
||||
register: _constraint_file
|
||||
with_items:
|
||||
- dest: "{{ _venv_build_requirements_prefix }}-requirements.txt"
|
||||
content: |-
|
||||
{% for item in _venv_pip_packages | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
- dest: "{{ _venv_build_requirements_prefix }}-global-constraints.txt"
|
||||
content: |-
|
||||
{% for item in venv_build_global_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
- dest: "{{ _venv_build_requirements_prefix }}-source-constraints.txt"
|
||||
content: |-
|
||||
{% for item in venv_build_constraints | select() %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
register: _requirements_contraints
|
||||
|
||||
- name: Upgrade the wheel build virtualenv pip/setuptools/wheel to the versions we want
|
||||
pip:
|
||||
|
@ -106,7 +86,8 @@
|
|||
- setuptools
|
||||
- wheel
|
||||
state: "{{ venv_pip_package_state }}"
|
||||
executable: "{{ venv_build_host_venv_path }}/bin/pip"
|
||||
virtualenv: "{{ venv_build_host_venv_path }}"
|
||||
virtualenv_command: "{{ venv_python_executable }} -m venv"
|
||||
extra_args: >-
|
||||
--constraint {{ _venv_build_requirements_prefix }}-global-constraints.txt
|
||||
--constraint {{ _venv_build_requirements_prefix }}-source-constraints.txt
|
||||
|
@ -123,7 +104,7 @@
|
|||
delay: 2
|
||||
|
||||
- name: Build wheels and constraints file
|
||||
when: (_requirement_file is changed) or (_global_constraint_file is changed) or (_constraint_file is changed)
|
||||
when: _requirements_contraints.results | selectattr('changed') | length > 0
|
||||
block:
|
||||
- name: Clean up temporary wheel build path
|
||||
file:
|
||||
|
|
Loading…
Reference in New Issue