11
11

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.

VagrantにFabricでプロビジョニング

Posted at

Chefは使ったことがなく、Puppetは忘れたので、お手軽そうなFabricでプロビジョニングしてみた。

fabricインストール

ホスト側に入れる

$ sudo easy_install pip
$ sudo pip install fabric

vagrant-fabricインストール

Vagrantのプラグインを入れる

$ vagrant plugin vagrant-fabric
$ vagrant plugin list
vagrant-fabric (0.2.2)

Vagrantfile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "CentOS6.5"
  config.vm.provision :fabric do |fabric|
    fabric.fabfile_path = "./fabfile.py"
    fabric.tasks = ["init"]
  end
end

fabfile.py

# -*- coding: utf-8 -*

from fabric.api import local, run, env

env.user = "root"

def package():
  run("yum -y update")
  run("yum -y groupinstall 'Development tools'")
  run("yum -y install wget git openssl-devel")

def iptables():
  run("chkconfig iptables off")
  run("service iptables stop")

def locale():
  run("yum -y groupinstall 'Japanese Support'")
  run("echo 'LANG=\"ja_JP.UTF-8\"\nSYSFONT=\"latarcyrheb-sun16\"' > /etc/sysconfig/i18n")
  run("echo 'export LANG=ja_JP.UTF-8' >> ~/.bash_profile")

def clock():
  run("cp -fp /usr/share/zoneinfo/Japan /etc/localtime")
  run("echo 'ZONE=\"Asia/Tokyo\"' > /etc/sysconfig/clock")

def mysql():
  run("yum -y remove mysql*")
  run("yum -y install http://repo.mysql.com/mysql-community-release-el6-4.noarch.rpm")
  run("yum -y install mysql-community-server")
  run("chkconfig mysqld on")

def ruby():
  run("git clone https://github.com/sstephenson/rbenv.git ~/.rbenv")
  run("echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> ~/.bash_profile")
  run("echo 'eval \"$(rbenv init -)\"' >> ~/.bash_profile")
  run("source ~/.bash_profile")
  run("git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build")
  run("rbenv install -v 2.1.2")
  run("rbenv rehash")
  run("rbenv global 2.1.2")
  run("echo 'export PATH=\"$HOME/.rbenv/versions/2.1.2/bin:$PATH\"' >> ~/.bash_profile")
  run("gem install bundler")

def jq():
  run("curl -o /usr/local/bin/jq http://stedolan.github.io/jq/download/linux64/jq")
  run("chmod 755 /usr/local/bin/jq")

def twurl():
  run("gem install twurl")

def init():
  package()
  iptables()
  locale()
  clock()
  mysql()
  ruby()
  jq()
  twurl()

プロビジョニングを適用

$ vagrant up --provision
11
11
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
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?