├── .travis.yml ├── LICENSE ├── README.md ├── defaults └── main.yml ├── meta └── main.yml ├── tasks ├── debian │ └── pyenv.yml ├── main.yml ├── osx │ └── pyenv.yml ├── pyenv.yml └── versions.yml ├── templates └── versions.j2 └── tests ├── inventory └── tests.yml /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: "2.7" 3 | 4 | os: 5 | - linux 6 | - osx 7 | 8 | install: 9 | - pip install ansible 10 | 11 | # Add ansible.cfg to pick up roles path. 12 | - "printf '[defaults]\\nroles_path = ../' > ansible.cfg" 13 | 14 | script: 15 | # Check the syntax. 16 | - ansible-playbook -i tests/inventory tests/tests.yml --syntax-check 17 | 18 | # Run the role. 19 | - ansible-playbook -i tests/inventory tests/tests.yml --connection=local --sudo 20 | 21 | # Check the files. 22 | - grep -Fxq "$(pyenv init -)" ~/.bashrc 23 | 24 | # Check for idempotence. 25 | - > 26 | ansible-playbook -i tests/inventory tests/tests.yml --connection=local --sudo 27 | | grep -q 'changed=0.*failed=0' 28 | && (echo 'Idempotence test: pass' && exit 0) 29 | || (echo 'Idempotence test: fail' && exit 1) 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Andy Dirnberger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pyenv 2 | ===== 3 | 4 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 5 | 6 | [![Build Status](https://travis-ci.org/dirn/ansible-pyenv.svg?branch=master)](https://travis-ci.org/dirn/ansible-pyenv) 7 | 8 | An Ansible role to install [pyenv](https://github.com/yyuu/pyenv). 9 | 10 | Requirements 11 | ------------ 12 | 13 | This role works on OS X and Debian-based OSes. If using OS X, make sure you have 14 | [Homebrew](http://brew.sh/) installed before running the role. If you're looking 15 | for a role to handle it for you, check out 16 | [dirn.homebrew](https://github.com/dirn/ansible-homebrew). 17 | 18 | Role Variables 19 | -------------- 20 | 21 | Several variables are available to configure the role. 22 | 23 | To set where pyenv will be installed: 24 | 25 | pyenv_root: ~/.pyenv 26 | 27 | To set the location of your projects: 28 | 29 | pyenv_project_root: '~' 30 | 31 | > This is useful if you want a different version of Python than you use 32 | > elsewhere. 33 | 34 | To specify the name of the run commands file that will initialize pyenv: 35 | 36 | pyenv_runcom: ~/.bashrc 37 | 38 | To specify which versions of Python to install: 39 | 40 | pyenv_versions: [] 41 | 42 | To specify the default versions of Python available: 43 | 44 | pyenv_default_versions: [] 45 | 46 | To specify alternative default versions of Python available inside your projects 47 | root: 48 | 49 | pyenv_project_versions: [] 50 | 51 | > This is useful if you want a different version of Python than you use 52 | > elsewhere. 53 | 54 | To install [virtualenv](https://github.com/yyuu/pyenv-virtualenv) and 55 | [virtualenvwrapper](https://github.com/yyuu/pyenv-virtualenvwrapper): 56 | 57 | pyenv_virtualenv: true 58 | 59 | Dependencies 60 | ------------ 61 | 62 | None. 63 | 64 | Example Playbook 65 | ---------------- 66 | 67 | - hosts: servers 68 | roles: 69 | - role: dirn.pyenv 70 | pyenv_runcom: ~/.zshrc 71 | pyenv_versions: 72 | - 2.7.9 73 | - 3.4.3 74 | - pypy-2.5.0 75 | - pypy3-2.4.0 76 | pyenv_default_versions: 77 | - 2.7.9 78 | - pypy-2.5.0 79 | pyenv_project_versions: 80 | - 3.4.3 81 | - pypy3-2.4.0 82 | 83 | License 84 | ------- 85 | 86 | MIT 87 | 88 | Author Information 89 | ------------------ 90 | 91 | This role was created by [Andy Dirnberger](https://github.com/dirn). 92 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | pyenv_root: ~/.pyenv 3 | pyenv_project_root: '~' 4 | 5 | pyenv_runcom: ~/.bashrc 6 | 7 | pyenv_versions: [] 8 | pyenv_default_versions: [] 9 | pyenv_project_versions: [] 10 | 11 | pyenv_virtualenv: true 12 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Andy Dirnberger 4 | description: Installs and configures pyenv. 5 | company: 6 | license: MIT 7 | min_ansible_version: 1.4 8 | platforms: 9 | - name: GenericUNIX 10 | versions: 11 | - all 12 | - any 13 | categories: 14 | - development 15 | - system 16 | dependencies: [] 17 | -------------------------------------------------------------------------------- /tasks/debian/pyenv.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install requirements 3 | apt: pkg={{ item }} state=present 4 | with_items: 5 | - make 6 | - build-essential 7 | - libssl-dev 8 | - zlib1g-dev 9 | - libbz2-dev 10 | - libreadline-dev 11 | - libsqlite3-dev 12 | - wget 13 | - curl 14 | - llvm 15 | 16 | - name: Install 17 | git: repo=https://github.com/yyuu/pyenv.git dest={{ pyenv_root }} 18 | 19 | - name: Install virtualenv 20 | git: repo=https://github.com/yyuu/{{ item }}.git dest={{ pyenv_root }}/plugins/{{ item }} 21 | with_items: 22 | - pyenv-virtualenv 23 | - pyenv-virtualenvwrapper 24 | when: pyenv_virtualenv 25 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - include: pyenv.yml 3 | 4 | - name: Install versions 5 | command: creates={{ pyenv_root }}/versions/{{ item }} pyenv install {{ item }} 6 | with_items: pyenv_versions 7 | 8 | - include: versions.yml 9 | versions: "{{ pyenv_default_versions }}" 10 | dest: "{{ pyenv_root }}/version" 11 | 12 | - include: versions.yml 13 | versions: "{{ pyenv_project_versions }}" 14 | dest: "{{ pyenv_project_root }}/.python-version" 15 | 16 | - name: Add to run commands 17 | lineinfile: > 18 | dest={{ pyenv_runcom }} 19 | state=present 20 | create=yes 21 | line="{{ item }}" 22 | with_items: 23 | - if which pyenv > /dev/null; then 24 | - " export PYENV_ROOT=\\\"$HOME/.pyenv\\\"" 25 | - " export PATH=\\\"$PYENV_ROOT/bin:$PATH\\\"" 26 | - " eval \\\"$(pyenv init -)\\\"" 27 | - "fi # pyenv" 28 | 29 | - name: Add virtualenv to run commands 30 | lineinfile: > 31 | dest={{ pyenv_runcom }} 32 | state=present 33 | create=yes 34 | insertbefore="fi # pyenv" 35 | line=" pyenv virtualenvwrapper_lazy" 36 | when: pyenv_virtualenv 37 | 38 | - name: Configure virtualenvwrapper 39 | lineinfile: > 40 | dest={{ pyenv_runcom }} 41 | state=present 42 | create=yes 43 | line="{{ item }}" 44 | with_items: 45 | - export WORKON_HOME=\"$HOME/.virtualenvs\" 46 | - export PROJECT_HOME=\"$HOME/development\" 47 | when: pyenv_virtualenv and pyenv_runcom 48 | -------------------------------------------------------------------------------- /tasks/osx/pyenv.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install 3 | homebrew: name=pyenv state=present 4 | 5 | - name: Install virtualenv 6 | homebrew: name={{ item }} state=present 7 | with_items: 8 | - pyenv-virtualenv 9 | - pyenv-virtualenvwrapper 10 | when: pyenv_virtualenv 11 | -------------------------------------------------------------------------------- /tasks/pyenv.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - include: debian/pyenv.yml 3 | when: ansible_os_family == 'Debian' 4 | 5 | - include: osx/pyenv.yml 6 | when: ansible_os_family == 'Darwin' 7 | -------------------------------------------------------------------------------- /tasks/versions.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Set versions 3 | template: src=../templates/versions.j2 dest={{ dest }} 4 | -------------------------------------------------------------------------------- /templates/versions.j2: -------------------------------------------------------------------------------- 1 | {% for version in versions -%} 2 | {{ version }} 3 | {% endfor %} 4 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost 2 | -------------------------------------------------------------------------------- /tests/tests.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | remote_user: root 4 | roles: 5 | - role: ansible-pyenv 6 | pyenv_version: [3.4.3, 2.7.9] 7 | pyenv_default_versions: [3.4.3] 8 | pyenv_project_versions: [2.7.9] 9 | --------------------------------------------------------------------------------