LoginSignup
27
28

More than 5 years have passed since last update.

centos6にansibleでpython環境を構築

Last updated at Posted at 2014-10-23

centos6にansibleでpython環境を構築

注)
手元の pyenvansible を入れる方法 ではない です。
手元の ansible から他所の centos サーバに pyenv 環境を作る方法です。

centos6 のデフォルトのpython環境が 2.6 だったので、
ansible-playbookpyenv で好きなバージョン入れられるようにしてみた。

pythonビルドに必要なパッケージyumで入れるあたりが若干めんどくさい。
ちょっと余計なのも入ってるけど。

vagrant でテストしたので、
user: vagrant
のところは適宜 sudo 権限あるユーザに書き換えて実行すればおk。

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
27
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
28