1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-04 23:37:12 +00:00

Setup pip path generic (#12045)

* setup_pip_path: use sysconfig to build pip scripts path generically

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* setup_pip_path: calculate PATH prepended with pip installation path

* move environment up to block

* obtain path from pip itself

* apparently the python interpreter doesnt go into ansible_facts

* rename role to setup_pip_scripts_path

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alexei Znamensky 2026-05-14 23:46:55 +12:00 committed by GitHub
parent 803b79b1da
commit 5447d0eb4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 3 deletions

View file

@ -0,0 +1,39 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Get facts
setup:
when: ansible_facts == {}
# pip._internal.locations.get_scheme() reflects pip's actual install scheme (e.g. RHEL root → /usr/local/bin),
# which can differ from sysconfig.get_path('scripts') (e.g. RHEL → /usr/bin).
- name: Get pip scripts path from current Python interpreter
ansible.builtin.command:
argv:
- "{{ ansible_python_interpreter }}"
- -c
- |
import sys
try:
from pip._internal.locations import get_scheme
print(get_scheme('pip').scripts)
except Exception:
import sysconfig
print(sysconfig.get_path('scripts'))
register: _pip_scripts_path
changed_when: false
- name: Build pip_path from env PATH and Python scripts dir
vars:
pip_path_list: >
{{ [_pip_scripts_path.stdout.strip()] + ansible_facts.env.PATH.split(":") }}
ansible.builtin.set_fact:
pip_scripts_path: >-
{{ pip_path_list | join(":") }}

View file

@ -4,5 +4,3 @@
azp/posix/2
destructive
skip/rhel # TODO executables are installed in /usr/local/bin, which isn't part of $PATH
skip/macos # TODO executables are installed in /Library/Frameworks/Python.framework/Versions/3.11/bin, which isn't part of $PATH

View file

@ -6,3 +6,4 @@
dependencies:
- setup_pkg_mgr
- setup_remote_tmp_dir
- setup_pip_scripts_path

View file

@ -8,7 +8,10 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- name: Install/Uninstall supervisorctl block
environment:
PATH: "{{ pip_scripts_path }}"
block:
- tempfile:
state: directory
suffix: supervisorctl-tests