$ wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ sudo rpm -Uvh epel-release-6-8.noarch.rpm
$ sudo yum -y install ansible $ ansible --version ansible 2.3.0.0
$ sudo yum -y install git $ sudo yum install patch
$ vi playbook.yml
--- - hosts: localhost connection: local sudo: yes vars: - python_version: 3.5.2 tasks: - name: disable iptables service: name=iptables state=stopped enabled=no - name: install libselinux-python yum: name=libselinux-python state=latest - name: remove localtime file: path=/etc/localtime state=absent - name: change timezone file: src=/usr/share/zoneinfo/Asia/Tokyo dest=/etc/localtime state=link force=yes mode=0644 - name: change locale lineinfile: >- dest=/etc/sysconfig/i18n state=present regexp=^LANG= line='LANG="ja_JP.UTF-8"' - name: install dependencies yum: name={{item}} state=present with_items: - gcc - openssl - openssl-devel - rpm-build - gcc-c++ - bzip2 - bzip2-devel - libtool - zlib - zlib-devel - httpd-devel - openssl-devel - curl-devel - ncurses-devel - gdbm-devel - readline - readline-devel - sqlite - sqlite-devel - libyaml-devel - libffi-devel - bison - name: check pyenv installed command: test -x /home/vagrant/.pyenv register: pyenv_present ignore_errors: yes become: no - name: git clone pyenv git: repo=https://github.com/yyuu/pyenv.git dest=/home/vagrant/.pyenv when: pyenv_present.rc != 0 become: no - name: check pyvirtual installed command: test -x /home/vagrant/.pyenv/plugins/pyenv-virtualenv register: pyvirtual_present ignore_errors: yes become: no - name: git clone pyenv-virtual git: repo=https://github.com/yyuu/pyenv-virtualenv.git dest=/home/vagrant/.pyenv/plugins/pyenv-virtualenv when: pyvirtual_present != 0 become: no - name: update pyenv command: git pull --rebase chdir=/home/vagrant/.pyenv become: no - name: update pyenv-virtualenv command: git pull --rebase chdir=/home/vagrant/.pyenv/plugins/pyenv-virtualenv become: no - name: check python installed shell: /bin/bash -lc "pyenv versions | grep {{python_version}}" register: python_installed ignore_errors: yes become: no - name: install python shell: /bin/bash -lc "pyenv install {{python_version}} && pyenv rehash && pyenv global {{python_version}}" when: python_installed.rc != 0 become: no
$ ansible-playbook playbook.yml
$ vi .bashrc
export PYENV_ROOT="${HOME}/.pyenv" if [ -d "${PYENV_ROOT}" ]; then export PATH=${PYENV_ROOT}/bin:$PATH eval "$(pyenv init -)" fi
$ source ~/.bashrc
$ ansible-playbook playbook.yml
$ python -V Python 3.5.2