summaryrefslogtreecommitdiffstats
path: root/roles/python/tasks/main.yml
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2025-08-20 18:07:25 +0200
committerAhmed Abdelhalim <[email protected]>2025-08-20 18:24:29 +0200
commit36ec6f1a3961abbbb41495dd4d141871f6675fea (patch)
treebf4d1c529cfac9ed9cfe267267d065b0a6506512 /roles/python/tasks/main.yml
parentb2eacfc041b548ec31422e2e902eaa227985c3c3 (diff)
Add python role
Diffstat (limited to 'roles/python/tasks/main.yml')
-rw-r--r--roles/python/tasks/main.yml49
1 files changed, 49 insertions, 0 deletions
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