-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-modules.yaml
More file actions
64 lines (54 loc) · 1.75 KB
/
python-modules.yaml
File metadata and controls
64 lines (54 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
- name: Detect Python version
command: "{{ python_bin }} -c 'import sys; print(\"{}.{}\".format(sys.version_info[0], sys.version_info[1]))'"
register: python_version_output
changed_when: false
- name: Set Python version fact
set_fact:
python_version: "{{ python_version_output.stdout }}"
- name: Ensure Python venv and dev packages are installed (Debian/Ubuntu)
package:
name:
- "python{{ python_version }}-venv"
- "python{{ python_version }}-dev"
state: present
when: ansible_os_family == 'Debian'
- name: Ensure Python venv and dev packages are installed (RedHat/Fedora)
package:
name:
- python3-devel
- python3-pip
state: present
when: ansible_os_family == 'RedHat'
- name: Create virtual environment
command: "{{ python_bin }} -m venv {{ venv_path }}"
args:
creates: "{{ venv_path }}"
become: true
- name: Ensure pip is available in the virtual environment
command: "{{ venv_path }}/bin/python -m ensurepip --upgrade"
args:
creates: "{{ venv_path }}/bin/pip"
become: true
- name: Upgrade pip and setuptools to avoid Python 3.12+ issues
command: "{{ venv_path }}/bin/pip install --upgrade pip setuptools"
become: true
changed_when: false
- name: Check pip version
command: "{{ venv_path }}/bin/pip --version"
register: pip_version
changed_when: false
- name: Show pip version
debug:
var: pip_version.stdout
- name: Install required Python modules in venv
pip:
name: "{{ item.name }}"
version: "{{ item.version | default(omit) }}"
executable: "{{ venv_path }}/bin/pip"
loop: "{{ python_modules }}"
when: python_modules is defined
become: true
- name: Set interpreter for later tasks
set_fact:
ansible_python_interpreter: "{{ venv_path }}/bin/python"