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 | 5e80f0bc555ffbe7203d0ab7dac0e759e0f3a217 (patch) | |
| tree | bf4d1c529cfac9ed9cfe267267d065b0a6506512 /roles/python/tasks | |
| parent | dd32fd1b254dedd48b983da9803d1f1dde3278f0 (diff) | |
Add python role
Diffstat (limited to 'roles/python/tasks')
| -rw-r--r-- | roles/python/tasks/main.yml | 49 |
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 |
