note) How to put ansible in your pyenv __ not __. __ How to create a pyenv environment from your ansible to another centos server __.
The default python environment for centos6 was 2.6, so I tried to put my favorite version with pyenv in ansible-playbook.
python It's a little annoying to put in the package yum required for build. There are some extras, though.
I tested it with vagrant, so
user: vagrant
You can rewrite the place as appropriate to a user with sudo authority and execute it.
python.yml
---
- hosts: servers
  user: vagrant
  vars:
    python_version: 2.7.6
  tasks:
  - name: install basic pkg
    yum: name={{item}} state=installed
    sudo: yes
    with_items:
    - vim
    - git
    - rsync
  - name: install build python package
    sudo: yes
    yum: name={{item}} state=installed
    with_items:
    - gcc
    - gcc-c++
    - patch
    - readline-devel
    - zlib-devel
    - openssl-devel
    ## for lxml
    - libxml2-devel
    - libxslt-devel
    ## for file copy
    - libselinux-python
  - name: install pyenv
    args:
      ## guard for only once.
      creates: ~/.pyenv
    shell: |
      git clone https://github.com/yyuu/pyenv.git ~/.pyenv
      ## add pyenv env
      (
          echo 'export PYENV_ROOT=~/.pyenv'
          echo 'export PATH=$PYENV_ROOT/bin:$PATH'
          echo 'eval "$(pyenv init -)"'
      ) >> ~/.bashrc
      source ~/.bashrc
      # install python
      pyenv install {{python_version}}
      pyenv rehash
      pyenv global {{python_version}}
  - name: pip install pkgs
    pip: name={{item}}
    with_items:
    - flask
    - lxml
    - uwsgi
        Recommended Posts