added pyenv role
This commit is contained in:
1
roles/avanov.pyenv/.gitignore
vendored
Normal file
1
roles/avanov.pyenv/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea/
|
16
roles/avanov.pyenv/.travis.yml
Normal file
16
roles/avanov.pyenv/.travis.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
language: python
|
||||||
|
python: "2.7"
|
||||||
|
#env:
|
||||||
|
before_install:
|
||||||
|
- sudo apt-get update -qq
|
||||||
|
- sudo apt-get install -qq python-apt python-pycurl
|
||||||
|
install:
|
||||||
|
- pip install ansible==1.9.4
|
||||||
|
script:
|
||||||
|
- echo localhost > inventory
|
||||||
|
- ansible-playbook -i inventory test.yml --syntax-check
|
||||||
|
- ansible-playbook -i inventory test.yml --connection=local --sudo -vvv --diff
|
||||||
|
- ansible-playbook -i inventory test_update.yml --syntax-check
|
||||||
|
- ansible-playbook -i inventory test_update.yml --connection=local --sudo -vvv --diff
|
||||||
|
#after_failure:
|
21
roles/avanov.pyenv/LICENSE
Normal file
21
roles/avanov.pyenv/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Maxim Avanov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
70
roles/avanov.pyenv/README.md
Normal file
70
roles/avanov.pyenv/README.md
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
avanov.pyenv
|
||||||
|
============
|
||||||
|
|
||||||
|
[](https://travis-ci.org/avanov/ansible-galaxy-pyenv)
|
||||||
|
|
||||||
|
|
||||||
|
Ansible Galaxy role for [pyenv](https://github.com/yyuu/pyenv) on Ubuntu / RedHat / OSX.
|
||||||
|
|
||||||
|
Install it with the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ansible-galaxy install avanov.pyenv
|
||||||
|
```
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
Here is the list of all variables and their default values:
|
||||||
|
|
||||||
|
* ``pyenv_env: "user"``
|
||||||
|
* ``pyenv_path: "{% if pyenv_env == 'user' %}{{ ansible_env.HOME }}/pyenv{% else %}/usr/local/pyenv{% endif %}"``
|
||||||
|
* ``pyenv_owner: "{{ ansible_env.USER }}"``
|
||||||
|
* ``pyenv_python_versions: ["3.4.1"]``
|
||||||
|
* ``pyenv_virtualenvs: [{ venv_name: "latest", py_version: "3.4.1" }]``
|
||||||
|
* ``pyenv_global: "3.4.1"``
|
||||||
|
* ``pyenv_update_git_install: no``
|
||||||
|
* ``pyenv_enable_autocompletion: no``
|
||||||
|
* ``pyenv_setting_path: "{% if pyenv_env == 'user' %}~/.bashrc{% else %}/etc/profile.d/pyenv.sh{% endif %}"``
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
- hosts: servers
|
||||||
|
roles:
|
||||||
|
- role: avanov.pyenv
|
||||||
|
pyenv_path: "{{ home }}/pyenv"
|
||||||
|
pyenv_owner: "{{ instance_owner }}"
|
||||||
|
pyenv_global: "3.6.5"
|
||||||
|
pyenv_update_git_install: no
|
||||||
|
pyenv_enable_autocompletion: no
|
||||||
|
pyenv_python_versions:
|
||||||
|
- "3.6.5"
|
||||||
|
- "3.4.1"
|
||||||
|
- "2.7.8"
|
||||||
|
pyenv_virtualenvs:
|
||||||
|
- venv_name: "latest_v3"
|
||||||
|
py_version: "3.4.1"
|
||||||
|
|
||||||
|
- venv_name: "latest_v2"
|
||||||
|
py_version: "2.7.8"
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Maxim Avanov (https://maximavanov.com/)
|
55
roles/avanov.pyenv/defaults/main.yml
Normal file
55
roles/avanov.pyenv/defaults/main.yml
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
# defaults file for pyenv
|
||||||
|
pyenv_env: "user"
|
||||||
|
pyenv_path: "{% if pyenv_env == 'user' %}{{ ansible_env.HOME }}/pyenv{% else %}/usr/local/pyenv{% endif %}"
|
||||||
|
pyenv_owner: "{{ ansible_env.USER }}"
|
||||||
|
pyenv_setting_path: "{% if pyenv_env == 'user' %}~/.bashrc{% else %}/etc/profile.d/pyenv.sh{% endif %}"
|
||||||
|
pyenv_update_git_install: no
|
||||||
|
pyenv_enable_autocompletion: no
|
||||||
|
pyenv_python_versions:
|
||||||
|
- 3.5.0
|
||||||
|
pyenv_virtualenvs:
|
||||||
|
- { venv_name: "latest", py_version: "3.5.0" }
|
||||||
|
# For a system install, the shims dir will not be writable by users, disable rehashing
|
||||||
|
pyenv_init_options: "{% if pyenv_env != 'user' %}--no-rehash{% endif %}"
|
||||||
|
|
||||||
|
pyenv_update: no
|
||||||
|
|
||||||
|
# additional options for the build process, e.g "--enable-shared"
|
||||||
|
pyenv_python_configure_opts: ""
|
||||||
|
|
||||||
|
pyenv_debian_packages:
|
||||||
|
- build-essential
|
||||||
|
- git
|
||||||
|
# On Ubuntu 12.04 build may fail with the following error:
|
||||||
|
# python-build: wget (< 1.14) doesn't support Server Name Indication.
|
||||||
|
# Please install curl (>= 7.18.1) and try again
|
||||||
|
- curl
|
||||||
|
- libssl-dev
|
||||||
|
- libbz2-dev
|
||||||
|
- libsqlite3-dev
|
||||||
|
- libreadline-dev
|
||||||
|
- zlib1g-dev
|
||||||
|
- wget
|
||||||
|
- llvm
|
||||||
|
- libncurses5-dev
|
||||||
|
- xz-utils
|
||||||
|
- tk-dev
|
||||||
|
- libxml2-dev
|
||||||
|
- libxmlsec1-dev
|
||||||
|
- libffi-dev
|
||||||
|
pyenv_redhat_packages:
|
||||||
|
- make
|
||||||
|
- git
|
||||||
|
- gcc
|
||||||
|
- libselinux-python
|
||||||
|
- zlib-devel
|
||||||
|
- openssl-devel
|
||||||
|
- bzip2-devel
|
||||||
|
- readline-devel
|
||||||
|
- libffi-devel
|
||||||
|
- sqlite-devel
|
||||||
|
- gdbm-devel
|
||||||
|
pyenv_osx_packages:
|
||||||
|
- readline
|
||||||
|
- xz
|
2
roles/avanov.pyenv/handlers/main.yml
Normal file
2
roles/avanov.pyenv/handlers/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# handlers file for pyenv
|
2
roles/avanov.pyenv/meta/.galaxy_install_info
Normal file
2
roles/avanov.pyenv/meta/.galaxy_install_info
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
install_date: Thu Sep 26 20:02:57 2019
|
||||||
|
version: 1.1.0
|
129
roles/avanov.pyenv/meta/main.yml
Normal file
129
roles/avanov.pyenv/meta/main.yml
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
---
|
||||||
|
galaxy_info:
|
||||||
|
author: Maxim Avanov
|
||||||
|
description: Ansible Galaxy role for pyenv (https://github.com/yyuu/pyenv).
|
||||||
|
company:
|
||||||
|
# Some suggested licenses:
|
||||||
|
# - BSD (default)
|
||||||
|
# - MIT
|
||||||
|
# - GPLv2
|
||||||
|
# - GPLv3
|
||||||
|
# - Apache
|
||||||
|
# - CC-BY
|
||||||
|
license: MIT
|
||||||
|
min_ansible_version: 2.0
|
||||||
|
#
|
||||||
|
# Below are all platforms currently available. Just uncomment
|
||||||
|
# the ones that apply to your role. If you don't see your
|
||||||
|
# platform on this list, let us know and we'll get it added!
|
||||||
|
#
|
||||||
|
platforms:
|
||||||
|
- name: macOS
|
||||||
|
versions:
|
||||||
|
- Sierra
|
||||||
|
|
||||||
|
- name: EL
|
||||||
|
versions:
|
||||||
|
# - all
|
||||||
|
# - 5
|
||||||
|
- 6
|
||||||
|
- 7
|
||||||
|
#- name: GenericUNIX
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - any
|
||||||
|
#- name: Fedora
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 16
|
||||||
|
# - 17
|
||||||
|
# - 18
|
||||||
|
# - 19
|
||||||
|
# - 20
|
||||||
|
#- name: opensuse
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 12.1
|
||||||
|
# - 12.2
|
||||||
|
# - 12.3
|
||||||
|
# - 13.1
|
||||||
|
# - 13.2
|
||||||
|
#- name: Amazon
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 2013.03
|
||||||
|
# - 2013.09
|
||||||
|
#- name: GenericBSD
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - any
|
||||||
|
#- name: FreeBSD
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 8.0
|
||||||
|
# - 8.1
|
||||||
|
# - 8.2
|
||||||
|
# - 8.3
|
||||||
|
# - 8.4
|
||||||
|
# - 9.0
|
||||||
|
# - 9.1
|
||||||
|
# - 9.1
|
||||||
|
# - 9.2
|
||||||
|
- name: Ubuntu
|
||||||
|
versions:
|
||||||
|
# - all
|
||||||
|
# - lucid
|
||||||
|
# - maverick
|
||||||
|
# - natty
|
||||||
|
# - oneiric
|
||||||
|
# - precise
|
||||||
|
# - quantal
|
||||||
|
# - raring
|
||||||
|
# - saucy
|
||||||
|
- trusty
|
||||||
|
- xenial
|
||||||
|
- yakkety
|
||||||
|
#- name: SLES
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 10SP3
|
||||||
|
# - 10SP4
|
||||||
|
# - 11
|
||||||
|
# - 11SP1
|
||||||
|
# - 11SP2
|
||||||
|
# - 11SP3
|
||||||
|
#- name: GenericLinux
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - any
|
||||||
|
#- name: Debian
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - etch
|
||||||
|
# - lenny
|
||||||
|
# - squeeze
|
||||||
|
# - wheezy
|
||||||
|
#
|
||||||
|
# Below are all categories currently available. Just as with
|
||||||
|
# the platforms above, uncomment those that apply to your role.
|
||||||
|
#
|
||||||
|
categories:
|
||||||
|
#- cloud
|
||||||
|
#- cloud:ec2
|
||||||
|
#- cloud:gce
|
||||||
|
#- cloud:rax
|
||||||
|
#- clustering
|
||||||
|
#- database
|
||||||
|
#- database:nosql
|
||||||
|
#- database:sql
|
||||||
|
- development
|
||||||
|
#- monitoring
|
||||||
|
#- networking
|
||||||
|
#- packaging
|
||||||
|
- system
|
||||||
|
#- web
|
||||||
|
dependencies: []
|
||||||
|
# List your role dependencies here, one per line. Only
|
||||||
|
# dependencies available via galaxy should be listed here.
|
||||||
|
# Be sure to remove the '[]' above if you add dependencies
|
||||||
|
# to this list.
|
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"
|
||||||
|
|
5
roles/avanov.pyenv/templates/.pyenvrc.j2
Normal file
5
roles/avanov.pyenv/templates/.pyenvrc.j2
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Include this file into your ~/.bashrc
|
||||||
|
# -------------------------------------
|
||||||
|
export PYENV_ROOT="{{ pyenv_path }}"
|
||||||
|
export PATH="$PYENV_ROOT/bin:$PATH"
|
||||||
|
eval "$(pyenv init - {{ pyenv_init_options}})"
|
8
roles/avanov.pyenv/test.yml
Normal file
8
roles/avanov.pyenv/test.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
- hosts: all
|
||||||
|
gather_facts: True
|
||||||
|
vars_files:
|
||||||
|
- 'defaults/main.yml'
|
||||||
|
tasks:
|
||||||
|
- debug:
|
||||||
|
msg: "Owner: {{ pyenv_owner }}"
|
||||||
|
- include: 'tasks/main.yml'
|
9
roles/avanov.pyenv/test_update.yml
Normal file
9
roles/avanov.pyenv/test_update.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
- hosts: all
|
||||||
|
gather_facts: True
|
||||||
|
vars_files:
|
||||||
|
- 'defaults/main.yml'
|
||||||
|
- 'tests/test_update_vars.yml'
|
||||||
|
tasks:
|
||||||
|
- debug:
|
||||||
|
msg: "Owner: {{ pyenv_owner }}"
|
||||||
|
- include: 'tasks/main.yml'
|
2
roles/avanov.pyenv/tests/test_update_vars.yml
Normal file
2
roles/avanov.pyenv/tests/test_update_vars.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
pyenv_update: yes
|
1
roles/avanov.pyenv/vars/main.yml
Normal file
1
roles/avanov.pyenv/vars/main.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
---
|
12
site.yml
12
site.yml
@ -5,4 +5,16 @@
|
|||||||
users:
|
users:
|
||||||
- username: '{{ primary_user }}'
|
- username: '{{ primary_user }}'
|
||||||
- nvim
|
- nvim
|
||||||
|
- role: avanov.pyenv
|
||||||
|
pyenv_path: $HOME/pyenv
|
||||||
|
pyenv_owner: "{{ primary_user }}"
|
||||||
|
pyenv_global: "system"
|
||||||
|
pyenv_python_versions:
|
||||||
|
- "3.7.4"
|
||||||
|
- "2.7.8"
|
||||||
|
pyenv_virtualenvs:
|
||||||
|
- venv_name: "latest_v3"
|
||||||
|
py_version: "3.7.4"
|
||||||
|
- venv_name: "latest_v2"
|
||||||
|
py_version: "2.7.8"
|
||||||
vars_files: ~/projects/ansible_vars/vars.yml
|
vars_files: ~/projects/ansible_vars/vars.yml
|
||||||
|
Reference in New Issue
Block a user