Skip to content

Commit a43441a

Browse files
committed
feature: tasks for installing Python
1 parent 8f187a9 commit a43441a

File tree

7 files changed

+135
-176
lines changed

7 files changed

+135
-176
lines changed

README.md

Lines changed: 25 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,40 @@
1-
# Ansible Role Template
1+
# Ansible Python Install
22

3-
[![Pipeline Status](https://github.com/Appsilon/ansible-role-template/actions/workflows/ci.yml/badge.svg)](https://github.com/Appsilon/ansible-role-template/actions/workflows/ci.yml)
3+
Install Python from source on Ubuntu-based systems (based on RStudio [docs](https://docs.rstudio.com/resources/install-python-source/)).
44

5-
This repository provides a base scaffolding template to use as a quick start of
6-
all Ansible roles at @Appsilon. Includes best practices that should always be
7-
used, like linter, tests, CI, etc.
5+
[![CI](https://github.com/Appsilon/ansible-python-install/workflows/CI/badge.svg)](https://github.com/Appsilon/ansible-python-install/actions/workflows/ci.yml)
6+
[![Ansible Galaxy](https://img.shields.io/badge/ansible--galaxy-name--of--my--role-blue.svg)](https://galaxy.ansible.com/appsilon/ansible-role-template)
87

9-
## How to Use
8+
## Requirements
109

11-
1. Click "[Use this
12-
template](https://github.com/Appsilon/ansible-role-template/generate)" to
13-
create a new repository from it.
14-
1. Update [`./meta/main.yml`](./meta/main.yml) with updated repository and role names.
15-
1. Update [`./role_README.md`](./role_README.md) with updated to repository and role name.
16-
1. Rename `./role_README.md` to `README.md`.
17-
1. Start coding! You're free to change anything.
10+
None.
1811

19-
## Development
12+
## Role Variables
2013

21-
### Dependencies
14+
| Variable | Required | Default | Choices | Comments |
15+
|-----------------|----------|------------------|-----------------------------------|---------------------------------------|
16+
| python_versions | yes | [3.10.6, 3.9.13] | Array with Python versions >= 3.7 | Version have to be specified as 3.x.y |
2217

23-
To execute tests locally, it is necessary to install the following
24-
dependencies:
18+
## Dependencies
2519

26-
* [Python](https://www.python.org/downloads/)
27-
* [Molecule](https://molecule.readthedocs.io/en/latest/installation.html)
20+
None.
2821

29-
### Preparing the Environment
22+
## Example Playbook
3023

31-
Create a Python environment:
32-
33-
```bash
34-
python3 -m venv .venv
35-
```
36-
37-
Activate the environment:
38-
39-
```bash
40-
source .venv/bin/activate
41-
```
42-
43-
Install molecule (and its dependencies) inside the environment:
44-
45-
```bash
46-
python3 -m pip install -r requirements.txt
47-
```
48-
49-
### Running
50-
51-
```bash
52-
molecule test
53-
```
54-
55-
To perform quick test after some modification:
56-
57-
```bash
58-
molecule create
59-
molecule converge
60-
molecule verify
61-
```
62-
63-
To log into the running instance for troubleshooting purposes:
64-
65-
```bash
66-
molecule login
67-
```
68-
69-
At the end of the test, destroy the environment:
70-
71-
```bash
72-
molecule destroy
73-
```
74-
75-
### Validation, Linters and Pull-Requests
76-
77-
We want to provide high quality code. For this reason we are using several
78-
[pre-commit hooks](.pre-commit-config.yaml) and [GitHub Actions
79-
workflow](.github/workflows/precommit.yaml). A pull-request to the `main`
80-
branch will trigger these validations and lints automatically. Please check your
81-
code before you will create pull-requests.
82-
83-
Before you can run hooks, you need to have the `pre-commit`
84-
[installed](https://pre-commit.com#install).
85-
86-
```bash
87-
pip install pre-commit
88-
pre-commit install
89-
```
90-
91-
If you are going to enforce [Conventional
92-
Commits](https://www.conventionalcommits.org/) commit message style on the title
93-
you will also need to
94-
[install](https://jorisroovers.com/gitlint/#getting-started) `gitlint`.
95-
96-
```bash
97-
pip install gitlint
98-
```
99-
100-
You then need to install the pre-commit hook like so:
101-
102-
```bash
103-
pre-commit install --hook-type commit-msg
24+
```yaml
25+
- hosts: all
26+
vars:
27+
python_versions:
28+
- 3.10.6
29+
- 3.7.8
30+
roles:
31+
- ansible-python-install
10432
```
10533
106-
> It's important that you run `pre-commit install --hook-type commit-msg`, even
107-
> if you've already used `pre-commit install` before. `pre-commit install` does
108-
> not install `commit-msg` hooks by default!
34+
## License
10935
110-
To manually trigger `gitlint` using `pre-commit` for your last commit message,
111-
use the following command:
36+
MIT
11237
113-
```sh
114-
pre-commit run gitlint --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG
115-
```
116-
117-
In case you want to change gitlint's behavior, you should either use a
118-
`.gitlint` file (see
119-
[Configuration](https://jorisroovers.com/gitlint/configuration)) or modify the
120-
gitlint invocation in your `.pre-commit-config.yaml` file like so:
121-
122-
```yaml
123-
- repo: https://github.com/jorisroovers/gitlint
124-
rev: # Fill in a tag / sha here
125-
hooks:
126-
- id: gitlint
127-
args: [--contrib=CT1, --msg-filename]
128-
```
38+
## Author Information
12939
130-
See [pre-commit documentation](https://pre-commit.com/) and [GitHub Actions
131-
documentation](https://docs.github.com/en/actions) for further details.
40+
[`Appsilon`](https://appsilon.com/)

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# defaults file
22
---
3+
python_versions:
4+
- 3.10.6
5+
- 3.9.13

meta/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# meta file
22
---
33
galaxy_info:
4-
role_name: fill_this_in
4+
role_name: python_install
55
author: appsilon
66
company: Appsilon
7-
description: fill_this_in
7+
description: Install Python from source
88
license: MIT
99
min_ansible_version: 2.11.1
1010
platforms:

role_README.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

tasks/install-python.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
3+
- name: Install additional python versions | install system dependencies
4+
ansible.builtin.apt:
5+
pkg: "{{ python_system_dependecies }}"
6+
state: "{{ apt_install_state | default('latest') }}"
7+
update_cache: true
8+
cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}"
9+
tags:
10+
- python-install-system-dependecies
11+
12+
- name: Install additional python versions | download python
13+
ansible.builtin.get_url:
14+
url: "https://www.python.org/ftp/python/{{ item }}/Python-{{ item }}.tgz"
15+
dest: "/tmp/Python-{{ item }}.tgz"
16+
mode: "0644"
17+
loop: "{{ python_versions }}"
18+
tags:
19+
- python-install-download-archives
20+
- python-install-setup-versions
21+
22+
- name: Install additional python versions | extract python
23+
ansible.builtin.unarchive:
24+
remote_src: true
25+
src: "/tmp/Python-{{ item }}.tgz"
26+
dest: "/tmp"
27+
loop: "{{ python_versions }}"
28+
tags:
29+
- python-install-extract-archives
30+
- python-install-setup-versions
31+
32+
- name: Install additional python versions | configure python
33+
ansible.builtin.command: >
34+
./configure \
35+
--prefix=/opt/python/{{ item }}
36+
--enable-shared
37+
--enable-ipv6
38+
LDFLAGS=-Wl,-rpath=/opt/python/{{ item }}/lib,--disable-new-dtags
39+
args:
40+
chdir: /tmp/Python-{{ item }}
41+
creates: /tmp/Python-{{ item }}/Makefile
42+
loop: "{{ python_versions }}"
43+
tags:
44+
- python-install-configure-python
45+
- python-install-setup-versions
46+
47+
- name: Install additional python versions | make python
48+
ansible.builtin.command: >
49+
make
50+
args:
51+
chdir: /tmp/Python-{{ item }}
52+
creates: /tmp/Python-{{ item }}/python-config
53+
loop: "{{ python_versions }}"
54+
tags:
55+
- python-install-make
56+
- python-install-setup-versions
57+
58+
- name: Install additional python versions | install python
59+
ansible.builtin.command: >
60+
make install
61+
args:
62+
chdir: /tmp/Python-{{ item }}
63+
creates: /opt/python/{{ item }}/bin/python3
64+
loop: "{{ python_versions }}"
65+
tags:
66+
- python-install-make-install
67+
- python-install-setup-versions
68+
69+
- name: Install additional python versions | download pip script
70+
ansible.builtin.get_url:
71+
url: "https://bootstrap.pypa.io/get-pip.py"
72+
dest: "/tmp/get-pip.py"
73+
mode: "0644"
74+
tags:
75+
- python-install-download-pip-script
76+
- python-install-setup-versions
77+
78+
- name: Install additional python versions | install pip
79+
ansible.builtin.command: >
80+
/opt/python/{{ item }}/bin/python3 /tmp/get-pip.py
81+
changed_when: false
82+
loop: "{{ python_versions }}"
83+
tags:
84+
- python-install-install-pip
85+
- python-install-setup-versions
86+
87+
- name: Install additional python versions | install virtualenv
88+
ansible.builtin.command: >
89+
/opt/python/{{ item }}/bin/pip install virtualenv
90+
args:
91+
creates: /opt/python/{{ item }}/bin/virtualenv
92+
loop: "{{ python_versions }}"
93+
tags:
94+
- python-install-install-virtualenv
95+
- python-install-setup-versions

tasks/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# tasks file
22
---
3-
- name: include variables
3+
- name: Include variables
44
ansible.builtin.include_vars: "{{ item }}"
55
with_first_found:
66
- "_{{ ansible_distribution_release }}.yml"
77
- "_{{ ansible_distribution | lower }}.yml"
88
- _default.yml
99
tags:
1010
- configuration
11+
12+
- include_tasks: install-python.yml

vars/_ubuntu.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# vars file
22
---
3+
python_system_dependecies:
4+
- build-essential
5+
- libffi-dev
6+
- libgdbm-dev
7+
- libsqlite3-dev
8+
- libssl-dev
9+
- zlib1g-dev

0 commit comments

Comments
 (0)