summaryrefslogtreecommitdiffstats
path: root/roles/python/tasks/main.yml
blob: ea78bed0a6d7170723f72cda5d870ed38823e2e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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