-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyenv.yml
138 lines (125 loc) · 4.3 KB
/
pyenv.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
#
# Ansible playbook: install pyenv v201506210608
# Louis T. Getterman IV (@LTGIV)
# www.GotGetLLC.com / www.opensour.cc/ggcom/ansible/playbooks/pyenv
#
# Example Usage:
# [user@host ~$] ansible-playbook ~/ggcom/ggcom-ansible-playbooks/ubuntu/pyenv.yml --extra-vars 'target=nameFromHostsFile user=nameOfUserUsingPyenv'
#
# Skip the prerequisites and go straight for the meat and potatoes:
# [user@host ~$] ansible-playbook ~/ggcom/ggcom-ansible-playbooks/ubuntu/pyenv.yml --extra-vars 'target=nameFromHostsFile user=nameOfUserUsingPyenv' --tags skipprereq
#
# See available versions for installing:
# [user@host ~$] pyenv install --list
#
# Setup a temporary directory using 1 of 2 methods (some VPS don't allow /tmp which mktemp tends to use)
# [user@host ~$] export TMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'dfwu'`
# [user@host ~$] mkdir -pv "$HOME/tmp"; export TMPDIR="$HOME/tmp";
#
# Install a Python version (most common choices are latest Python 2 or Python 3):
# (the following version number is the most recent for Python 2 at the time of this file being pushed to GitHub)
# [user@host ~$] pyenv install 2.7.9
#
# Create Python virtual environment
# [user@host ~$] pyenv virtualenv 2.7.9 my-virtual-env-Py2
#
# Setup virtual environment as global (or local)
# [user@host ~$] pyenv global my-virtual-env-Py2
#
# Thanks:
#
# pyenv install for CentOS 6.5 x86_64
# https://gist.github.com/ysaotome/7956676
#
# TODO: ACTION (DEFAULT IS INSTALL, BUT SHOULD ALSO HAVE UPDATE (pyenv update) AND REMOVE (rm -fr ~/.pyenv))
# TODO: ADDITIONAL SHELL/PROFILE SUPPORT INSTEAD OF DEFAULTING TO ~/.bash_profile
- hosts: '{{ target }}'
sudo: yes
tasks:
#---------- Install prerequisites
#----- Debian or Ubuntu
- name: Install pyenv prerequisites for Debian or Ubuntu
apt: >
update_cache=yes
pkg={{ item }}
state=installed
with_items:
- curl
- git-core
- gcc
- make
- zlib1g-dev
- libbz2-dev
- libreadline-dev
- libsqlite3-dev
- libssl-dev
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
# Needed for 2.7, but not 2.7.9
# - build-essential
# - wget
# - llvm
#----- Debian or Ubuntu
#----- CentOS
- name: Install Development Tools for Red Hat or CentOS
shell: "sudo yum -y groupinstall 'Development Tools'"
when: ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'CentOS' or ansible_distribution == 'SHMZ'
- name: Install pyenv prerequisites for Red Hat or CentOS
yum: >
update_cache=yes
pkg={{ item }}
state=present
with_items:
- bzip2-devel
- gcc
- gcc-c++
- git
- make
- openssl-devel
- patch
- readline-devel
- sqlite-devel
- zlib-devel
when: ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'CentOS' or ansible_distribution == 'SHMZ'
#-----/CentOS
#----------/Install prerequisites
- name: Running pyenv-installer by Yamashita, Yuu
shell: 'curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash'
args:
creates: '~/.pyenv/'
sudo_user: '{{ user }}'
register: retout
tags:
- skipprereq
- debug: var=retout.stdout_lines
tags:
- skipprereq
# other choice is ~/.profile?
- name: Load pyenv automatically in ~/.bash_profile
lineinfile: >
dest='~/.bash_profile'
line='{{ item }}'
create=yes
state=present
with_items:
- '# pyenv functionality (installed by ggcom-ansible-playbooks/ubuntu/pyenv.yml)'
- 'export PATH="$HOME/.pyenv/bin:$PATH"'
- 'eval "$(pyenv init -)"'
- 'eval "$(pyenv virtualenv-init -)"'
sudo_user: '{{ user }}'
tags:
- skipprereq
- name: Reloading ~/.bash_profile
shell: 'source ~/.bash_profile'
sudo_user: '{{ user }}'
tags:
- skipprereq
- name: Listing current Python versions (system should show up)
shell: 'pyenv versions'
sudo_user: '{{ user }}'
register: retout
tags:
- skipprereq
- debug: var=retout.stdout_lines
tags:
- skipprereq