diff --git a/defaults/main.yml b/defaults/main.yml index 0f3d154..c46387a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -83,7 +83,7 @@ venv_pip_build_env: {} venv_default_pip_install_args: >- {%- if (groups[venv_build_group] is defined) and (groups[venv_build_group] | length > 0) and (venv_wheel_build_enable | bool) %} --find-links {{ openstack_repo_url | default('http://localhost') }}/os-releases/{{ openstack_release | default('master') }}/{{ _venv_build_dist_arch }}/wheels - --trusted-host {{ (openstack_repo_url | default('http://localhost')) | urlsplit('hostname') }} + --trusted-host {{ (openstack_repo_url | default('http://localhost')) | urlsplit('hostname') -}} {%- endif %} # Arguments to pass to pip when installing into the venv diff --git a/handlers/main.yml b/handlers/main.yml index 8a88c3c..0cea342 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: venv changed +- name: Virtual Environment changed meta: noop when: false + listen: + - venv changed diff --git a/meta/main.yml b/meta/main.yml index 49cac16..99305f9 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -18,19 +18,21 @@ galaxy_info: description: Python venv preparation company: OpenStack license: Apache2 - min_ansible_version: 2.4 + role_name: python_venv_build + namespace: openstack + min_ansible_version: "2.10" platforms: - name: Debian versions: - - buster + - bullseye - name: Ubuntu versions: - - bionic - focal + - jammy - name: EL versions: - - 8 - categories: + - "9" + galaxy_tags: - cloud - python - development diff --git a/tasks/main.yml b/tasks/main.yml index aac2cf9..f9bcc9d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,7 +28,7 @@ tags: - always -- name: gather build target facts +- name: Gather build target facts setup: gather_subset: '!all:min' delegate_to: "{{ item }}" @@ -73,7 +73,8 @@ - venv_wheel_build_enable | bool - _venv_build_dist_arch not in venv_build_targets -- include_tasks: "python_venv_wheel_build.yml" +- name: Including python_venv_wheel_build tasks + include_tasks: "python_venv_wheel_build.yml" args: apply: tags: @@ -84,11 +85,13 @@ tags: - always -- import_tasks: "python_venv_install.yml" +- name: Including python_venv_install tasks + import_tasks: "python_venv_install.yml" tags: - install -- include_tasks: "python_venv_set_facts.yml" +- name: Including python_venv_set_facts tasks + include_tasks: "python_venv_set_facts.yml" args: apply: tags: diff --git a/tasks/python_venv_install.yml b/tasks/python_venv_install.yml index 7e1f186..8b9bc58 100644 --- a/tasks/python_venv_install.yml +++ b/tasks/python_venv_install.yml @@ -28,7 +28,18 @@ - name: Install distro packages for venv build package: - name: "{{ (venv_wheel_build_enable | bool) | ternary(venv_install_base_distro_package_list | union(venv_install_distro_package_list), (venv_build_base_distro_package_list | union(venv_build_distro_package_list) | union(venv_install_base_distro_package_list) | union(venv_install_distro_package_list))) }}" + name: >- + {{ + (venv_wheel_build_enable | bool) | ternary( + venv_install_base_distro_package_list | union(venv_install_distro_package_list), + ( + venv_build_base_distro_package_list | + union(venv_build_distro_package_list) | + union(venv_install_base_distro_package_list) | + union(venv_install_distro_package_list) + ) + ) + }} state: "{{ venv_distro_package_state }}" update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}" cache_valid_time: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary(venv_distro_cache_valid_time, omit) }}" @@ -51,6 +62,7 @@ file: path: "{{ venv_install_destination_path }}" state: directory + mode: "0755" # Note(jrosser) # If the constraints file from the wheel build has been previously collected @@ -84,6 +96,7 @@ copy: dest: "{{ item.dest }}" content: "{{ item.content }}" + mode: "0644" with_items: - dest: "{{ venv_install_destination_path }}/requirements.txt" content: |- diff --git a/tasks/python_venv_install_symlink.yml b/tasks/python_venv_install_symlink.yml index 0522852..82ab2a9 100644 --- a/tasks/python_venv_install_symlink.yml +++ b/tasks/python_venv_install_symlink.yml @@ -25,7 +25,12 @@ vars: _venv_python_major_version: "{{ (_python_venv_details.files[0].path | basename | split('.') )[0] }}" shell: >- - {{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('dpkg -L ' ~ (venv_packages_to_symlink | join(' ')), 'rpm -ql ' ~ (venv_packages_to_symlink | join(' ')) ) }} + {{ + (ansible_facts['pkg_mgr'] == 'apt') | ternary( + 'dpkg -L ' ~ (venv_packages_to_symlink | join(' ')), + 'rpm -ql ' ~ (venv_packages_to_symlink | join(' ')) + ) + }} | egrep '^.*{{ _venv_python_major_version }}.*/(site|dist)-packages/.*' | egrep -v "__pycache__" changed_when: false diff --git a/tasks/python_venv_set_facts.yml b/tasks/python_venv_set_facts.yml index d109e33..b24526d 100644 --- a/tasks/python_venv_set_facts.yml +++ b/tasks/python_venv_set_facts.yml @@ -18,6 +18,7 @@ file: path: /etc/ansible/facts.d state: directory + mode: "0755" - name: Record the necessary facts become: true @@ -26,6 +27,7 @@ section: "{{ item.section }}" option: "{{ item.option }}" value: "{{ item.value | string }}" + mode: "0644" with_items: "{{ venv_facts_when_changed }}" when: - (_install_venv_pip_packages is defined and diff --git a/tasks/python_venv_wheel_build.yml b/tasks/python_venv_wheel_build.yml index 9f02ebb..d6287de 100644 --- a/tasks/python_venv_wheel_build.yml +++ b/tasks/python_venv_wheel_build.yml @@ -50,6 +50,7 @@ state: directory owner: "{{ venv_build_host_user_name | default(omit) }}" group: "{{ venv_build_host_group_name | default(omit) }}" + mode: "0755" with_items: - "{{ venv_build_host_wheel_path }}" - "{{ venv_build_host_requirements_path }}" @@ -61,6 +62,7 @@ content: "{{ item.content }}" owner: "{{ venv_build_host_user_name | default(omit) }}" group: "{{ venv_build_host_group_name | default(omit) }}" + mode: "0644" with_items: - dest: "{{ _venv_build_requirements_prefix }}-requirements.txt" content: |- @@ -111,7 +113,7 @@ path: "/tmp/{{ venv_install_destination_path | basename }}" state: absent - - name: Build wheels for the packages to be installed into the venv + - name: Build wheels for the packages to be installed into the venv # noqa: no-changed-when command: >- {{ venv_build_host_venv_path }}/bin/pip wheel --requirement {{ _venv_build_requirements_prefix }}-requirements.txt @@ -147,6 +149,7 @@ - name: Move built wheels to common wheel path shell: >- mv /tmp/{{ venv_install_destination_path | basename }}/* {{ venv_build_host_wheel_path }}/ + changed_when: false args: executable: /bin/bash @@ -160,3 +163,4 @@ dest: "{{ _venv_build_requirements_prefix }}-constraints.txt" owner: "{{ venv_build_host_user_name | default(omit) }}" group: "{{ venv_build_host_group_name | default(omit) }}" + mode: "0644" diff --git a/vars/main.yml b/vars/main.yml index 543e6fa..6cc154a 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -55,7 +55,7 @@ venv_build_targets: |- {% endfor %} {{ targets }} -_venv_wheels_play_hosts: | +_venv_wheels_play_hosts: |- {% set wheel_groups = {} %} {% for host in ansible_play_hosts %} {% set arch = hostvars[host]['ansible_facts']['architecture'] %} @@ -70,7 +70,7 @@ _venv_wheels_play_hosts: | {% endfor %} {{ wheel_groups }} -_venv_wheels_first_play_hosts: | +_venv_wheels_first_play_hosts: |- {% set first_hosts = [] %} {% for distro_arch_hosts in _venv_wheels_play_hosts.values() %} {% set _ = first_hosts.append(distro_arch_hosts | first) %} @@ -79,6 +79,11 @@ _venv_wheels_first_play_hosts: | _venv_pip_packages: "{{ (venv_default_pip_packages | union(venv_pip_packages)) | sort | select | list }}" -_venv_build_dist_arch: "{{ (ansible_facts['distribution'] | lower) | replace(' ', '_') }}-{{ ansible_facts['distribution_version'].split('.')[:2] | join('.') }}-{{ ansible_facts['architecture'] | lower }}" +_venv_build_dist_arch: >- + {{ + ((ansible_facts['distribution'] | lower) | replace(' ', '_')) ~ '-' ~ + (ansible_facts['distribution_version'].split('.')[:2] | join('.')) ~ '-' ~ + (ansible_facts['architecture'] | lower) + }} _venv_build_requirements_prefix: "{{ venv_build_host_requirements_path }}/{{ venv_install_destination_path | basename }}"