Skip to content

Commit

Permalink
Merge pull request #15 from Rheinwerk/PT-187411386-virtualenv-ansible…
Browse files Browse the repository at this point in the history
…-core

[#187411386] Install Python3.12 in virtualenv and use it
  • Loading branch information
eifelmicha authored Jun 5, 2024
2 parents dfb776a + e96beb7 commit 5fd54d6
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 22 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,27 @@ None.
Dependencies
------------

None.
Python 3.12 and Pip installed. You can use the following ansible tasks to ensure requirements are met:

```yaml
- name: Add Deadsnakes APT repository
ansible.builtin.apt_repository:
repo: ppa:deadsnakes/ppa

- name: Install python3.12 via APT
ansible.builtin.apt:
state: present
update_cache: true
name:
- python3.12
- python3.12-dev
- python3.12-venv

- name: Install python3-pip via APT
ansible.builtin.apt:
state: present
name: python3-pip
```
Example Playbook
Expand Down
3 changes: 0 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@

_ansible:
ansible_version: ""
jinja2_version: ""
markupsafe_version: ""
requests_version: ""
36 changes: 36 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Converge
hosts: all
become: true

pre_tasks:
- name: Update APT Cache
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
register: result
until: result is succeeded
when: ansible_os_family == 'Debian'

- name: Add Deadsnakes APT repository
ansible.builtin.apt_repository:
repo: ppa:deadsnakes/ppa

- name: Install python3.12 via APT
ansible.builtin.apt:
state: present
update_cache: true
name:
- python3.12
- python3.12-dev
- python3.12-venv

- name: Install python3-pip via APT
ansible.builtin.apt:
state: present
name: python3-pip

tasks:
- name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
ansible.builtin.include_role:
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
48 changes: 30 additions & 18 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
---
#
# tasks file for ansible-role-ansible
#
# vim:et:ts=2:ft=ansible

- name: Install dependencies via APT
ansible.builtin.apt:
state: present
name:
- "{{ 'python-pip' if ansible_distribution_version in ['14.04', '18.04'] else 'python3-pip' }}"
- "{{ 'python-dev' if ansible_distribution_version in ['14.04', '18.04'] else 'python3-dev' }}"
- libffi-dev
- libssl-dev

- name: Install Ansible and dependencies via PIP
ansible.builtin.pip:
name:
- "MarkupSafe{{ _ansible.markupsafe_version | default('') }}"
- netaddr
- boto
- boto3
- botocore
- passlib
- "Jinja2{{ _ansible.jinja2_version | default('') }}"
- "requests{{ _ansible.requests_version | default('') }}"
# Required for Postgres
- psycopg2-binary
# Required for MySQL
- PyMySQL
# Required for different Ansible modules
- requests
- wheel
- "ansible-core{{ _ansible.ansible_version | default('') }}"
virtualenv_command: /usr/bin/python3.12 -m venv /opt/ansible_virtualenv
virtualenv: /opt/ansible_virtualenv

- name: Create symbolic links
ansible.builtin.file:
src: "/opt/ansible_virtualenv/bin/{{ item }}"
dest: "/usr/bin/{{ item }}"
owner: root
group: root
state: link
loop:
- ansible
- ansible-config
- ansible-connection
- ansible-console
- ansible-doc
- ansible-galaxy
- ansible-inventory
- ansible-playbook
- ansible-pull
- ansible-test
- ansible-vault

0 comments on commit 5fd54d6

Please sign in to comment.