Last active
September 12, 2017 06:29
-
-
Save yubessy/f97bb404c6d088bef7ffcc3506adf3d3 to your computer and use it in GitHub Desktop.
Ansible pyenv role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
pyenv_root: /opt/pyenv | |
pyenv_rcfiles: [] | |
pyenv_versions: [] | |
pyenv_global_version: system | |
pyenv_build_requirements: | |
# https://github.com/pyenv/pyenv/wiki/Common-build-problems | |
- zlib-devel | |
- bzip2 | |
- bzip2-devel | |
- readline-devel | |
- sqlite | |
- sqlite-devel | |
- openssl-devel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- include: pyenv.yml | |
- include: versions.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: pyenv requirements are installed | |
yum: | |
name: '{{ item }}' | |
state: present | |
with_items: '{{ pyenv_build_requirements }}' | |
- name: pyenv repo exists | |
git: | |
repo: https://github.com/pyenv/pyenv.git | |
dest: '{{ pyenv_root }}' | |
- name: pyenv init commands are configured | |
blockinfile: | |
dest: '{{ item }}' | |
create: yes | |
content: | | |
{{ lookup('template', 'templates/pyenv_init.j2') }} | |
with_items: '{{ pyenv_rcfiles }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: pyenv temporal init script file is created | |
tempfile: | |
prefix: ansible.pyenv.init. | |
register: tmp_pyenv_init | |
changed_when: false | |
- name: pyenv temporal init commands are configured | |
blockinfile: | |
dest: '{{ tmp_pyenv_init.path }}' | |
content: | | |
{{ lookup('template', 'templates/pyenv_init.j2') }} | |
changed_when: false | |
- name: installed python versions are checked | |
shell: 'source {{ tmp_pyenv_init.path }} && pyenv versions --bare' | |
changed_when: false | |
register: tmp_pyenv_versions | |
- name: missing python versions are installed | |
shell: 'source {{ tmp_pyenv_init.path }} && pyenv install {{ item }}' | |
when: item not in tmp_pyenv_versions.stdout_lines | |
with_items: '{{ pyenv_versions }}' | |
- name: global python version is checked | |
shell: 'source {{ tmp_pyenv_init.path }} && pyenv global' | |
changed_when: false | |
register: tmp_pyenv_global_version | |
- name: global python version is set | |
shell: 'source {{ tmp_pyenv_init.path }} && pyenv global {{ pyenv_global_version }}' | |
when: pyenv_global_version != tmp_pyenv_global_version.stdout | |
- name: unused python versions are uninstalled | |
shell: 'source {{ tmp_pyenv_init.path }} && pyenv uninstall -f {{ item }}' | |
when: item not in pyenv_versions | |
with_items: '{{ tmp_pyenv_versions.stdout_lines }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/pyenv/pyenv#installation | |
export PYENV_ROOT="{{ pyenv_root }}" | |
export PATH="$PYENV_ROOT/bin:$PATH" | |
eval "$(pyenv init -)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment