I started Python. I found that there is a convenient thing called pyenv as well as rbenv. The usage was almost the same, so I made it a playbook.
ansible is 2.0.2. Python to put is 3.5.1.
main.yml
---
- hosts: localhost # hostname
become: no
gather_facts: no
vars:
python_version: "3.5.1"
tasks:
- include: tasks/python.yml
tasks/python.yml
---
- 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'
Very easy. (Although it is a shell script that is not very beautiful)
If you hit this for the time being, you can put pyenv and put python 3.5.1 and set it up.
After that, manually write ʻeval $ (pyenv init)in
.bash_profile` etc. and you're done.
In my case, I take dotfiles to various places, so
if [ `which pyenv` ]; then
eval "$(pyenv init - --no-rehash)" # adding --no-rehash makes this faster
fi
It is said.
I've made a Mac provisioner that includes this Python preference, so if you're interested, please.
ikuwow/mac-provision: Provisioner of My Mac. https://github.com/ikuwow/mac-provision
Recommended Posts