AnsibleでRailsが動く環境をDigital Oceanに作る(3)rubyの設定周辺を変更

January 11, 2015

*作業メモ的な不完全な記事です。あとでまとめを書くかもしれません。

前回の続きです。

rbenvのインストール方法を変更

Vagrant で Ruby on Rails の環境を構築するまでの手順 - Qiitaを参考に、/usr/local/にインストールすることにした。

しかし、こんなエラーが出るように。。。

Installing ruby-2.1.5…

BUILD FAILED (CentOS Linux 7 using ruby-build 20141225)

ログを見たらCのコンパイラがないということだったので、commonにgccを追加しました。

configure: error: in `/tmp/ruby-build.20150111130746.13201/ruby-2.1.5’: configure: error: no acceptable C compiler found in $PATH

さらに、The Ruby openssl extension was not compiled.とか言われたので、commonにopenssl-devlを入れました。さっきはなんでこれなしでインストール出来てたんだろう。。

最終的に、roles/ruby/tasks/main.ymlはこうなりました。

-—

  • name: install ruby yum: name=ruby state=present
  • name: check out rbenv git: repo={{ rbenv.repo }} dest=/usr/local/rbenv accept_hostkey=yes
  • name: add /usr/local/rbenv/bin to $PATH lineinfile: dest=/etc/profile line=export\ PATH=“/usr/local/rbenv/bin:$PATH” regexp=PATH.*rbenv create=yes
  • name: add rbenv init lineinfile: dest=/etc/profile line=eval\ \”$(rbenv\ init\ -)\” regexp=eval.*rbenv create=yes
  • name: checkout ruby-build as rbenv plugin git: repo={{ rubybuild.repo }} dest=/usr/local/rbenv/plugins/ruby-build accept_hostkey=yes
  • name: install ruby-build shell: /usr/local/rbenv/plugins/ruby-build/install.sh
  • name: install libffi-devel for CentOS7.0 yum: name=libffi-devel state=present
  • name: check whether a specific version of ruby is installed or not shell: /usr/local/rbenv/bin/rbenv versions | grep {{ ruby.version }} | tr ’*’ ’ ’ | sed -e ‘s/\s\+//’ | cut -f1 -d’ ’ register: rbenv_version
  • name: install ruby with rbenv command: /usr/local/rbenv/bin/rbenv install {{ ruby.version }} when: rbenv_version.stdout != ”{{ ruby.version }}”
  • name: set ruby version global command: /usr/local/rbenv/bin/rbenv global {{ ruby.version }}
  • name: update gems command: /usr/local/rbenv/bin/rbenv exec gem update —system
  • name: install bundler gem command: /usr/local/rbenv/bin/rbenv exec gem install bundler —no-ri —no-rdoc
  • name: rbenv rehash command: /usr/local/rbenv/bin/rbenv rehash

現時点での、roles/common/tasks/main.ymlはこのような感じです。

-—

  • name: create iptables template: src=my_iptables.j2 dest=/etc/sysconfig/iptables
  • name: update all packages yum: name=* state=latest
  • name: install git yum: name=git state=present
  • name: install gcc yum: name=gcc state=present
  • name: install openssl yum: name={{ item }} state=present with_items:

    • openssl
    • openssl-devel

少しずつ、ansibleに慣れていく感がある…。

参考

はじめてのAnsible試行錯誤記録


Profile picture

Written by morizotter who lives and works in Tokyo building useful things. You should follow them on Twitter