suzuki-shunsuke.pyenv-module
ansible-pyenv-module
This is an Ansible module for running pyenv
commands.
You can find it here: Ansible Galaxy
Important Notice
- This module does not support "check mode."
Supported Platforms
- Generic Linux
- MacOSX
We have tested this module on:
- Ubuntu 16.04 (using Vagrant and Virtualbox)
- CentOS 7.3 (using Vagrant and Virtualbox)
- MacOS Sierra 10.12.5
Requirements
- pyenv
- Necessary Python build dependencies
- pyenv-virtualenv: Needed if you want to use
virtualenv
orvirtualenvs
.
If you'd like to install pyenv and Python build dependencies using an Ansible role, check out suzuki-shunsuke.pyenv. For installing pyenv-virtualenv with an Ansible role, look at suzuki-shunsuke.pyenv-virtualenv.
Supported pyenv Commands and Options
Here are some of the available pyenv
commands:
$ pyenv install [-s] [-f] <version>
$ pyenv uninstall -f <version>
$ pyenv install -l
$ pyenv versions [--bare]
$ pyenv global
$ pyenv global <version> [<version> ...]
$ pyenv virtualenv [-f] [options] [version] <virtualenv-name>
$ pyenv virtualenvs [--bare] [--skip-aliases]
Installation
To install the module, run:
$ ansible-galaxy install suzuki-shunsuke.pyenv-module
In your playbook (playbook.yml
), you can use it like this:
- hosts: default
roles:
- suzuki-shunsuke.pyenv-module
Options
For additional information, refer to the pyenv command reference and run pyenv help <command>
for command-specific help.
Common Options
Name | Type | Required | Default | Choices / Example | Description |
---|---|---|---|---|---|
subcommand | str | no | install | [install, uninstall, versions, global, virtualenvs, virtualenv] | |
pyenv_root | str | no | ~/.pyenv | Required if "PYENV_ROOT" environment variable is not set. | |
expanduser | bool | no | yes | Filters PYENV_ROOT and "pyenv_root" using os.path.expanduser . |
"install" Command Options
Parameter | Type | Required | Default | Choices / Example | Description |
---|---|---|---|---|---|
version | str | no | 3.6.1 | Version to install. | |
list | bool | no | no | Use -l to list versions. | |
skip_existing | bool | no | yes | Use -s to skip if already installed. | |
force | bool | no | no | Use -f to force installation. |
You need either "version" or "list" option.
"uninstall" Command Options
Parameter | Type | Required | Default | Choices / Example | Description |
---|---|---|---|---|---|
version | str | yes | 2.7.13 | Version to uninstall. |
"global" Command Options
Parameter | Type | Required | Default | Choices | Description |
---|---|---|---|---|---|
versions | list | no | Set global versions. |
"versions" Command Options
Parameter | Type | Required | Default | Choices | Description |
---|---|---|---|---|---|
bare | bool | no | yes | Use --bare to list without extra information. |
"virtualenvs" Command Options
Parameter | Type | Required | Default | Choices | Description |
---|---|---|---|---|---|
skip_aliases | bool | no | yes | Skip showing aliases. | |
bare | bool | no | yes | Use --bare to list without extra information. |
"virtualenv" Command Options
When using pyenv-virtualenv
, it may use either python -m venv
or the virtualenv
command.
Common Options
Parameter | Type | Required | Default | Example | Description |
---|---|---|---|---|---|
force | bool | no | no | Force creation. | |
version | str | yes | 2.7.13 | Python version for the virtualenv. | |
virtualenv_name | str | yes | ansible | Name of the virtualenv. |
Notice: The force option may not behave as expected.
virtualenv
Options
Refer to virtualenv documentation for more options.
python -m venv
Options
Refer to the official venv documentation for more options.
Example
Here are some examples of using the pyenv
module in a playbook:
- name: Install Python 3.6.1
pyenv:
version: 3.6.1
pyenv_root: "~/.pyenv"
- name: Force install Python 3.6.1
pyenv:
version: 3.6.1
pyenv_root: "~/.pyenv"
force: yes
- name: Uninstall Python 2.6.9
pyenv:
subcommand: uninstall
version: 2.6.9
pyenv_root: "~/.pyenv"
- name: Set global version to Python 3.6.1
pyenv:
subcommand: global
versions:
- 3.6.1
pyenv_root: "~/.pyenv"
Tips
Installing Python Packages with pip
This module does not directly support the pip
command, but you can achieve this with the official pip module.
Example:
- name: Install Python 2.7.13
pyenv:
pyenv_root: "{{pyenv_root}}"
version: 2.7.13
- name: Create virtualenv 3.6.1
pyenv:
subcommand: virtualenv
pyenv_root: "{{pyenv_root}}"
version: 3.6.1
virtualenv_name: yaml_env
- name: Install ansible using pip
pip:
name: ansible
executable: "{{pyenv_root}}/versions/2.7.13/bin/pip"
- name: Install pyyaml in the virtualenv "yaml_env"
pip:
name: pyyaml
executable: "{{pyenv_root}}/versions/yaml_env/bin/pip"
Change Log
Check CHANGELOG.md for updates.
See Also
- suzuki-shunsuke.pyenv: Ansible role to install pyenv.
- suzuki-shunsuke.pyenv-virtualenv: Ansible role to install pyenv-virtualenv.
License
Development
Requirements
- Vagrant
- Ansible
- Node.js
- Yarn
Setup
$ yarn install
$ cd tests
$ ansible-galaxy install -r roles.yml
Testing
$ cd tests
$ vagrant up --provision
ansible-galaxy install suzuki-shunsuke.pyenv-module