项目作者: suzuki-shunsuke

项目描述 :
ansible module to run pyenv command
高级语言: Python
项目地址: git://github.com/suzuki-shunsuke/ansible-pyenv-module.git
创建时间: 2017-07-01T08:49:17Z
项目社区:https://github.com/suzuki-shunsuke/ansible-pyenv-module

开源协议:MIT License

下载


ansible-pyenv-module

Build Status

ansible module to run pyenv command.

https://galaxy.ansible.com/suzuki-shunsuke/pyenv-module/

Notice

Supported platform

  • GenericLinux
  • MacOSX

We test this module in

  • Ubuntu 16.04 (Vagrant, Virtualbox)
  • CentOS 7.3 (Vagrant, Virtualbox)
  • MaxOS Sierra 10.12.5

Requirements

If you want to install pyenv and python build dependencies with ansible role, we recommend the suzuki-shunsuke.pyenv.
And if you want to install pyenv-virtualenv with ansible role, we recommend the suzuki-shunsuke.pyenv-virtualenv.

Supported pyenv subcommands and options

  1. $ pyenv install [-s] [-f] <version>
  2. $ pyenv uninstall -f <version>
  3. $ pyenv install -l
  4. $ pyenv versions [--bare]
  5. $ pyenv global
  6. $ pyenv global <version> [<version> ...]
  7. $ pyenv virtualenv [-f] [--no-pip] [--no-setuptools] [--no-wheel] [--symlinks] [--copies] [--clear] [--without-pip] [version] <virtualenv-name>
  8. $ pyenv virtualenvs [--bare] [--skip-aliases]

Install

  1. $ ansible-galaxy install suzuki-shunsuke.pyenv-module
  1. # playbook.yml
  2. - hosts: default
  3. roles:
  4. # After you call this role, you can use this module.
  5. - suzuki-shunsuke.pyenv-module

Options

In addition to this document, please see pyenv command reference and the output of pyenv help <command> command also.

Common Options

name type required default choices / example description
subcommand str no install [install, uninstall, versions, global, virtualenvs, virtualenv]
pyenv_root str no ~/.pyenv If the environment variable “PYENV_ROOT” is not set, this option is required
expanduser bool no yes By default the environment variable PYENV_ROOT and “pyenv_root” option are filtered by os.path.expanduser

Options of the “install” subcommand

parameter type required default choices / example description
version str no 3.6.1
list bool no no -l option
skip_existing bool no yes -s option
force bool no no -f option

Either “version” or “list” option is required.
If the “list” option is set, the return value of that task has “versions” field.

Options of the “uninstall” subcommand

parameter type required default choices / example description
version str yes 2.7.13

Options of the “global” subcommand

parameter type required default choices description
versions list no

The return value of the “global” subcommand has “versions” field.

Options of the “versions” subcommand

parameter type required default choices description
bare bool no yes

The return value of the “versions” subcommand has “versions” field.

Options of the “virtualenvs” subcommand

parameter type required default choices description
skip_aliases bool no yes
bare bool no yes

The return value of the “virtualenvs” subcommand has “virtualenvs” field.

Options of the “virtualenv” subcommand

https://github.com/pyenv/pyenv-virtualenv#virtualenv-and-venv

pyenv-virtualenv uses python -m venv if it is available and the virtualenv command is not available.

options of the “virtualenv” subcommand depend on whether pyenv-virtualenv uses python -m venv or not.

Common options

parameter type required default example description
force bool no no
version str yes 2.7.13
virtualenv_name str yes ansible
Notice: force option doesn’t work as expected

This is pyenv-virtualenv’s problem.

https://github.com/pyenv/pyenv-virtualenv/issues/161

virtualenv options

parameter type required default example description
always_copy bool no no
no_pip bool no no
no_setuptools bool no no
no_wheel bool no no

See the virtualenv official documentation and the output of the virtualenv --help command.

python -m venv options

parameter type required default example description
clear bool no no
copies bool no no
symlinks bool no no
without_pip bool no no

See the venv official documentation and the output of the python -m venv -h command.

Notice: clear option doesn’t work as expected

This is pyenv-virtualenv’s problem.

Example

  1. - name: pyenv install -s 3.6.1
  2. pyenv:
  3. version: 3.6.1
  4. pyenv_root: "~/.pyenv"
  5. - name: pyenv install -f 3.6.1
  6. pyenv:
  7. version: 3.6.1
  8. pyenv_root: "~/.pyenv"
  9. force: yes
  10. - name: pyenv uninstall -f 2.6.9
  11. pyenv:
  12. subcommand: uninstall
  13. version: 2.6.9
  14. pyenv_root: "~/.pyenv"
  15. - name: pyenv global 3.6.1
  16. pyenv:
  17. subcommand: global
  18. versions:
  19. - 3.6.1
  20. pyenv_root: "~/.pyenv"
  21. - name: pyenv global
  22. pyenv:
  23. subcommand: global
  24. pyenv_root: "~/.pyenv"
  25. register: result
  26. - debug:
  27. var: result.versions
  28. - name: pyenv install -l
  29. pyenv:
  30. list: yes
  31. pyenv_root: "{{ansible_env.HOME}}/.pyenv"
  32. register: result
  33. - debug:
  34. var: result.versions
  35. - name: pyenv versions --bare
  36. pyenv:
  37. subcommand: versions
  38. pyenv_root: "{{ansible_env.HOME}}/.pyenv"
  39. register: result
  40. - debug:
  41. var: result.versions
  42. - name: pyenv virtualenvs --skip-aliases --bare
  43. pyenv:
  44. subcommand: virtualenvs
  45. pyenv_root: "~/.pyenv"
  46. register: result
  47. - debug:
  48. var: result.virtualenvs
  49. - name: pyenv virtualenv --force 2.7.13 ansible
  50. pyenv:
  51. subcommand: virtualenv
  52. pyenv_root: "~/.pyenv"
  53. version: 2.7.13
  54. virtualenv_name: ansible
  55. force: yes

Tips

Install python packages with pip

Now this module doesn’t support pip subcommand,
but you can do it with the official pip module.

  1. # install python and create virtualenv before using pip module
  2. - name: pyenv install -s 2.7.13
  3. pyenv:
  4. pyenv_root: "{{pyenv_root}}"
  5. version: 2.7.13
  6. - name: pyenv virtualenv 3.6.1 yaml_env
  7. pyenv:
  8. subcommand: virtualenv
  9. pyenv_root: "{{pyenv_root}}"
  10. version: 3.6.1
  11. virtualenv_name: yaml_env
  12. # use pip module with executable option
  13. - name: install ansible
  14. pip:
  15. name: ansible
  16. executable: "{{pyenv_root}}/versions/2.7.13/bin/pip"
  17. - name: install pyyaml on the virtualenv "yaml_env"
  18. pip:
  19. name: pyyaml
  20. executable: "{{pyenv_root}}/versions/yaml_env/bin/pip"

Change Log

See CHANGELOG.md.

See also

Licence

MIT

Develop

Requirements

  • Vagrant
  • Ansible
  • Node.js
  • yarn

Setup

  1. $ yarn install
  2. $ cd tests
  3. $ ansible-galaxy install -r roles.yml

Test

  1. $ cd tests
  2. $ vagrant up --provision