Vagrant èµ·åæã«1åã ãå®è¡ããã¹ã¯ãªãããè¨å®ãã
å¼ç¤¾ã§ã¯ãµã¼ãã®æ§æ管çã« Chef ãå°å ¥ãã¦ãã¾ããæè¿ãããã¨ãã㧠Chef ã®åå¼·ä¼ãéããã¦ããããã¨ã³ã¸ãã¢ç³»ããã°ã§ãç®ã«ããããããã¨ãå¢ãã¦ãã¾ããããã¾ã æ¥æ¬ã§ã®äºä¾ãå°ãªãããã«æãã¾ãã
ä»å㯠Chef ã¨ã»ããã§èªããã Vagrantã«ã¤ãã¦æ¸ããã¨æãã¾ããChef ã® Recipe ã Cookbook ã試ãã¨ãã«ã¯ãã¼ã«ã«ç°å¢ãä½ãããã® VM ç°å¢ä¸ã§å®è¡ãããã¨ã«ãªãã¾ããããããæå©ããã¦ãããã®ã Vagrant ã§ããVagrant 㯠VirtualBox 㮠CUI ã©ããã¼ã¨ããä½ç½®ã¥ãã«ãªããé常ã«ç°¡åã« VM ãä½æãããã¨ãã§ãã¾ããããã§ã¯Â Vagrant ã®è©³ãã使ãæ¹ã«è§¦ãã¾ããã®ã§ãããç¥ãããæ¹ã¯Â Software Design (ã½ããã¦ã§ã¢ ãã¶ã¤ã³) 2012å¹´ 10æå·) ãä¼è¤ç´ä¹ãããåºããã¦ããÂ å ¥éChef Solo â Infrastructure as Code ãåèã«ããã¨ããã¨æãã¾ãã
ãã¦ããã® Vagrant ã¯ä»¥ä¸ã®ã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãããã¨ãã§ãã¾ãã
$ gem install vagrant
ã¤ã³ã¹ãã¼ã«ãããã¨ã«ãã£ã¦ vagrant ã¨ããã³ãã³ããå©ç¨ã§ããããã«ãªãã¾ããå®éã«ä½¿ãã¨ãã«ã¯ vagrant init ãªã©ãµãã³ãã³ããä¸ãã¦ããã¾ããvagrant init ãããã£ã¬ã¯ããªã«ã¯ Vagrantfile ã¨ãã VM èµ·åã«å¿ è¦ãªè¨å®ãã¡ã¤ã«ãä½æãããããã§ããããã®ãã¡ã¤ã«ã« VM ã®ç´°ããªè¨å®ãå ¥ãã¦ããããã¨ãã§ãã¾ããã¾ã Vagrant èªä½ã Chef Solo ã¨ã®é£æºãèãã¦ä½ããã¦ãããããç¹å®ã® Cookbook ãå®è¡ãããã¨ã容æã§ãã
ããããä»åã¯ãVM ã Vagrant ããèµ·åããã¨ãã«æåã®1åã ãã¹ã¯ãªãããå®è¡ãããã¨ãããã¨ãè¨å®ãã¦ã¿ããã¨æãã¾ããVM ã®èµ·å㯠vagrant up ã³ãã³ãã使ãã®ã§ãããååã ãâ¯â¯ããã¨ããè¨å®ã¯èªåã§é å¼µã£ã¦æ¸ããããªãããã§ããç§ã¯ Proxy è¨å®ãå¿ è¦ãªç°å¢ä¸ã§ã¯ãã®è¨å®ããªããªãèªååã§ããã«å°ã£ã¦ãã¾ããããVagrant ã§ã·ã§ã«ã¹ã¯ãªãããå®è¡ã§ããã¨ãããã¨ãç¥ã£ãã®ã§ãã·ã§ã«ã¹ã¯ãªããå ã§å¤æããããã¨æãã¾ããã
Vagrantfile ã§ã¯ãã®ããã« VM èµ·åæã®å®è¡ããã·ã§ã«ã¹ã¯ãªãããæå®ãã¦ããã¾ãã
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :hostonly, "192.168.33.10"
# vagrant up ã®ã¨ãã« bootstrap.sh ã¨ããã¹ã¯ãªãããå®è¡ãã
config.vm.provision :shell, :path => "bootstrap.sh"
end
次ã«ãå®éã«å¼ã°ããã·ã§ã«ã¹ã¯ãªãã bootstrap.sh ãç¨æãã¾ãã
#!/usr/bin/env bash
HTTP_PROXY="proxy.example.com:8000"
HTTPS_PROXY="$HTTP_PROXY"
# Exit if already bootstrapped
test -f /etc/bootstrapped && exit
echo "Setting HTTP Proxy for /etc/environment"
cat <> /etc/environment
http_proxy="http://$HTTP_PROXY/"
https_proxy="https://$HTTPS_PROXY/"
EOM
echo "Setting HTTP Proxy for /etc/apt/apt.conf"
test ! -f /etc/apt/apt.conf; touch /etc/apt/apt.conf
cat <> /etc/apt/apt.conf
Acquire::http::proxy "http://$HTTP_PROXY/";
Acquire::https::proxy "https://$HTTPS_PROXY/";
EOM
echo "Setting HTTP Proxy for cURL in Vagrant user directory"
if test -d /home/vagrant; then
cat < /home/vagrant/.curlrc
proxy = $HTTP_PROXY
EOM
fi
echo "Installing chef from deb package to use chef-solo"
test ! -d /etc/repository/setup; mkdir -p /etc/repository/setup
cp /vagrant/chef_11.4.0-1.ubuntu.11.04_amd64.deb /etc/repository/setup
dpkg -i /etc/repository/setup/chef_11.4.0-1.ubuntu.11.04_amd64.deb
date > /etc/bootstrapped
Proxy å¨ãã¯æå¤ã¨åä»ã§ãããã¤ãã®è¨å®ããã¦ãããå¿ è¦ãããã¾ãããã® bootstrap.sh ã§ã¯ãã²ã¨ã¾ãããã£ã¦ããç¯å²ã§è¨å®ãã¦ãã¾ãã
- ã°ãã¼ãã«ç°å¢å¤æ°
- apt ãå©ç¨ããè¨å®
- vagrant ã¦ã¼ã¶ã curl ããã¨ãã®è¨å®
ããã« VM ãå©ç¨ãã Chef ããã±ã¼ã¸ãäºãã»ããã¢ããããããã«ãã¦ãã¾ã (ãã¼ã¹ã¨ãã VM ã«ãããã¨æãã¾ãããããè¨è¿°ãã¦ãã precise64 ã§ã¯æå㧠Chef ããã±ã¼ã¸ãå ¥ããå¿ è¦ããã£ãã®ã§æ¸ãã¦ãã¾ã)
ãã® bootstrap.sh 㯠vagrant up ããã¨ãã«å¿ ãå¼ã°ããããã«ãªãã¾ãããã¹ã¯ãªããã®å é ã§
# Exit if already bootstrapped
test -f /etc/bootstrapped >> exit
ã¨ããåå²ããã¦ããããã2åç®ä»¥éã¯ã¹ãããããããã«ãªãã¾ãã