mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-06 08:17:11 +00:00
* 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>
39 lines
1.4 KiB
YAML
39 lines
1.4 KiB
YAML
---
|
|
####################################################################
|
|
# 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(":") }}
|