You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
2.4 KiB

---
- name: Check if the correct version of Python is already installed
stat:
path: /usr/local/bin/python{{ python_version }}
register: python_binary
- name: Download and install Python
when: not python_binary.stat.exists
block:
- name: Download Python source code
get_url:
dest: /tmp/python.tar.gz
url: https://www.python.org/ftp/python/{{ python_full_version }}/Python-{{ python_full_version }}.tgz
checksum: sha256:e0fbd5b6e1ee242524430dee3c91baf4cbbaba4a72dd1674b90fda87b713c7ab
- name: Create temp directory to extract Python to
file:
path: /tmp/python
state: directory
- name: Extract Python
unarchive:
remote_src: true
src: /tmp/python.tar.gz
dest: /tmp/python
extra_opts:
- --strip-components=1
- name: Install build dependencies for Python
apt:
name:
- make
- build-essential
- libssl-dev
- zlib1g-dev
- libbz2-dev
- libreadline-dev
- libsqlite3-dev
- wget
- curl
- llvm
- libncurses5-dev
- libncursesw5-dev
- xz-utils
- tk-dev
- name: Build and install Python (this can take a long time)
shell:
chdir: /tmp/python
cmd: |
./configure --enable-optimizations --with-ensurepip=install
make
make altinstall
- name: Create dir for venvs
file:
path: /opt/venvs
state: directory
owner: "{{ app_username }}"
group: "{{ app_username }}"
mode: 0755
- name: Install packages needed for compiling psycopg2
apt:
name:
- gcc
- libpq-dev
- name: Create venv
become_user: "{{ app_username }}"
command:
cmd: python{{ python_version }} -m venv {{ venv_dir }}
creates: "{{ venv_dir }}"
- name: Check installed packages in venv
command:
cmd: "{{ bin_dir }}/pip freeze"
register: pip_freeze
changed_when: false
- name: Install Python packages into venv
become_user: "{{ app_username }}"
pip:
executable: "{{ bin_dir }}/pip"
requirements: "{{ app_dir }}/{{ pip_requirements_filename }}"
- name: Install Tildes into venv as editable
become_user: "{{ app_username }}"
pip:
executable: "{{ bin_dir }}/pip"
name: "{{ app_dir }}"
editable: true
when: "'-e '+app_dir not in pip_freeze.stdout_lines"