27
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?