diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-08-20 18:07:25 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-08-20 18:24:29 +0200 |
| commit | 36ec6f1a3961abbbb41495dd4d141871f6675fea (patch) | |
| tree | bf4d1c529cfac9ed9cfe267267d065b0a6506512 /roles | |
| parent | b2eacfc041b548ec31422e2e902eaa227985c3c3 (diff) | |
Add python role
Diffstat (limited to 'roles')
| -rw-r--r-- | roles/python/defaults/main.yml | 3 | ||||
| -rw-r--r-- | roles/python/meta/argument_specs.yml | 13 | ||||
| -rw-r--r-- | roles/python/meta/main.yml | 19 | ||||
| -rw-r--r-- | roles/python/tasks/main.yml | 49 |
4 files changed, 84 insertions, 0 deletions
diff --git a/roles/python/defaults/main.yml b/roles/python/defaults/main.yml new file mode 100644 index 00000000..b9639318 --- /dev/null +++ b/roles/python/defaults/main.yml @@ -0,0 +1,3 @@ +--- +python_global_version: "system" +python_versions: [] diff --git a/roles/python/meta/argument_specs.yml b/roles/python/meta/argument_specs.yml new file mode 100644 index 00000000..ef13b7c8 --- /dev/null +++ b/roles/python/meta/argument_specs.yml @@ -0,0 +1,13 @@ +--- +argument_specs: + main: + options: + python_global_version: + type: "str" + description: "The pyenv python global version to use, default: system" + default: "system" + python_versions: + type: "list" + description: "The python versions to install" + elements: "str" + default: [] diff --git a/roles/python/meta/main.yml b/roles/python/meta/main.yml new file mode 100644 index 00000000..bf7913e2 --- /dev/null +++ b/roles/python/meta/main.yml @@ -0,0 +1,19 @@ +--- +dependencies: + - role: "homebrew" +galaxy_info: + author: "a14m" + description: "Install pyenv, pipx and python (versions) on Linux distributions" + company: "kartoffeln.work GmbH." + license: "MIT" + min_ansible_version: "2.18" + platforms: + - name: "ArchLinux" + versions: + - "all" + - name: "Ubuntu" + versions: + - "noble" + - name: "Debian" + versions: + - "bookworm" diff --git a/roles/python/tasks/main.yml b/roles/python/tasks/main.yml new file mode 100644 index 00000000..ea78bed0 --- /dev/null +++ b/roles/python/tasks/main.yml @@ -0,0 +1,49 @@ +--- +- name: "Install pyenv and pipx" + community.general.homebrew: + name: + - "pyenv" + - "pipx" + state: "present" + +- name: "Add pyenv to shell profile" + ansible.builtin.blockinfile: + path: "{{ ansible_env.HOME }}/.bashrc" + state: "present" + prepend_newline: true + append_newline: true + marker: "# ==== {mark} ANSIBLE PYENV CONFIG" + block: | + if command -v pyenv 1>/dev/null 2>&1; then + export PYENV_ROOT="$HOME/.pyenv" + export PATH="$PYENV_ROOT/bin:$PATH" + eval "$(pyenv init - bash)" + fi + +- name: "Add pipx to shell profile" + ansible.builtin.blockinfile: + path: "{{ ansible_env.HOME }}/.bashrc" + state: "present" + prepend_newline: true + append_newline: true + marker: "# ==== {mark} ANSIBLE PIPX CONFIG" + block: | + if command -v pipx 1>/dev/null 2>&1; then + export PATH="$PATH:$HOME/.local/bin" + fi + +- name: "Install python versions" + ansible.builtin.command: + cmd: "pyenv install {{ item }}" + args: + creates: "{{ ansible_env.HOME }}/.pyenv/versions/{{ item }}*/bin/python" + environment: + PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}" + with_items: "{{ python_versions | default([]) }}" + +- name: "Set global python version" + ansible.builtin.command: + cmd: "pyenv global {{ python_global_version }}" + environment: + PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}" + changed_when: false |
