Created
April 25, 2016 10:52
-
-
Save ikuwow/7d2a5aa69cb0cd2b22c8767f6c939b37 to your computer and use it in GitHub Desktop.
Macでpyenv使ってPythonの環境設定をするansible playbook ref: http://qiita.com/ikuwow/items/4a1d784876f70a1abd74
This file contains hidden or 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
if [ `which pyenv` ]; then | |
eval "$(pyenv init - --no-rehash)" # adding --no-rehash makes this faster | |
fi |
This file contains hidden or 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
--- | |
- hosts: localhost # hostname | |
become: no | |
gather_facts: no | |
vars: | |
python_version: "3.5.1" | |
tasks: | |
- include: tasks/python.yml |
This file contains hidden or 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: Install basic python packages | |
homebrew: name=pyenv | |
- name: Check installed Python version | |
shell: "pyenv versions | grep {{python_version}} > /dev/null; echo $?" | |
ignore_errors: true | |
register: python_is_installed | |
changed_when: python_is_installed.stdout != '0' | |
- name: Install Python | |
shell: "pyenv install {{python_version}}" | |
args: | |
creates: ~/.pyenv/versions/{{python_version}}/bin/python | |
- name: Check Python version | |
shell: "python --version | grep {{python_version}} > /dev/null; echo $?" | |
register: is_correct_version | |
changed_when: is_correct_version.stdout != '0' | |
- name: Switch Python version | |
shell: "pyenv global {{python_version}} && pyenv rehash" | |
when: is_correct_version.stdout != '0' | |
- name: pyenv init | |
shell: 'eval "$(pyenv init -)"' | |
changed_when: is_correct_version.stdout != '0' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment