added pyenv role
This commit is contained in:
5
roles/avanov.pyenv/tasks/Darwin.yml
Normal file
5
roles/avanov.pyenv/tasks/Darwin.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: Install development packages necessary for building Python
|
||||
homebrew:
|
||||
name: "{{ pyenv_osx_packages }}"
|
||||
state: present
|
||||
become: false
|
12
roles/avanov.pyenv/tasks/Debian.yml
Normal file
12
roles/avanov.pyenv/tasks/Debian.yml
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: Ensure apt cache is up to date
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: "{{ 48 * 60 * 60 }}" # consider the cache to be valid within 48 hours
|
||||
become: true
|
||||
|
||||
- name: Install development packages necessary for building Python
|
||||
apt:
|
||||
pkg: "{{ pyenv_debian_packages }}"
|
||||
state: present
|
||||
become: true
|
8
roles/avanov.pyenv/tasks/RedHat.yml
Normal file
8
roles/avanov.pyenv/tasks/RedHat.yml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
# Use action module which can interchangably use yum or dnf depending on what is available ( Eg. dnf on Fedora vs yum on Centos )
|
||||
# Note: special variable ansible_pkg_mgr requires fact_gathering to be enabled
|
||||
# More: https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing_packages/
|
||||
- name: Install development packages necessary for building Python
|
||||
action: >
|
||||
{{ ansible_pkg_mgr }} name="{{ pyenv_redhat_packages }}" state=present
|
||||
become: true
|
59
roles/avanov.pyenv/tasks/install.yml
Normal file
59
roles/avanov.pyenv/tasks/install.yml
Normal file
@ -0,0 +1,59 @@
|
||||
---
|
||||
- name: Install PyEnv
|
||||
git:
|
||||
repo: https://github.com/pyenv/pyenv.git
|
||||
dest: "{{ pyenv_path }}"
|
||||
update: "{{ pyenv_update_git_install }}"
|
||||
|
||||
- name: Install PyEnv-virtualenv plugin
|
||||
git:
|
||||
repo: https://github.com/yyuu/pyenv-virtualenv.git
|
||||
dest: "{{ pyenv_path }}/plugins/pyenv-virtualenv"
|
||||
update: "{{ pyenv_update_git_install }}"
|
||||
|
||||
- name: Install PyEnv-update plugin
|
||||
git:
|
||||
repo: https://github.com/pyenv/pyenv-update.git
|
||||
dest: "{{ pyenv_path }}/plugins/pyenv-update"
|
||||
update: "{{ pyenv_update_git_install }}"
|
||||
when: pyenv_update
|
||||
|
||||
- name: Install .pyenvrc
|
||||
template:
|
||||
src: ".pyenvrc.j2"
|
||||
dest: "{{ pyenv_path }}/.pyenvrc"
|
||||
owner: "{{ pyenv_owner }}"
|
||||
mode: "0644"
|
||||
|
||||
- name: "Load pyenv env variables in {{ pyenv_setting_path }}"
|
||||
lineinfile: dest="{{ pyenv_setting_path }}"
|
||||
regexp="\.pyenvrc$"
|
||||
line="source {{ pyenv_path }}/.pyenvrc"
|
||||
state=present
|
||||
create=yes
|
||||
|
||||
- name: "Add pyenv autocomplete in {{ pyenv_setting_path }}"
|
||||
lineinfile: dest="{{ pyenv_setting_path }}"
|
||||
regexp="pyenv\.bash$"
|
||||
line="source {{ pyenv_path }}/completions/pyenv.bash"
|
||||
state=present
|
||||
when: pyenv_enable_autocompletion
|
||||
|
||||
- name: Update Pyenv interpreter list
|
||||
shell: . {{ pyenv_path }}/.pyenvrc && pyenv update
|
||||
when: pyenv_update
|
||||
|
||||
- name: Install Python interpreters "{{ pyenv_python_versions }}"
|
||||
shell: . {{ pyenv_path }}/.pyenvrc && env PYTHON_CONFIGURE_OPTS="{{ pyenv_python_configure_opts }}" pyenv install {{ item }}
|
||||
creates="{{ pyenv_path }}/versions/{{ item }}/bin/python"
|
||||
with_items: "{{ pyenv_python_versions }}"
|
||||
|
||||
- name: Create virtual environments
|
||||
shell: . {{ pyenv_path }}/.pyenvrc && pyenv virtualenv {{ item.py_version }} {{ item.venv_name }}
|
||||
creates="{{ pyenv_path }}/versions/{{ item.venv_name }}/bin/python"
|
||||
with_items: "{{ pyenv_virtualenvs }}"
|
||||
|
||||
- name: Set pyenv global
|
||||
shell: . {{ pyenv_path }}/.pyenvrc && pyenv global {{ pyenv_global }} && pyenv rehash
|
||||
when: pyenv_global is defined
|
||||
|
20
roles/avanov.pyenv/tasks/main.yml
Normal file
20
roles/avanov.pyenv/tasks/main.yml
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
- include: Darwin.yml
|
||||
when: ansible_os_family == "Darwin"
|
||||
|
||||
- include: Debian.yml
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- include: RedHat.yml
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
|
||||
- include: install.yml
|
||||
become: true
|
||||
become_user: "{{ pyenv_owner }}"
|
||||
when: pyenv_env == "user"
|
||||
|
||||
- include: install.yml
|
||||
become: true
|
||||
when: pyenv_env == "system"
|
||||
|
Reference in New Issue
Block a user