エロサイトの作り方

2013年11月から勉強しながらエロサイトを作っています。

Ansibleで環境構築(1) - Vagrantを入れる

先日、GMOクラウドVPSの環境でアップデート後に再起動を要求されたので再起動かけたら二度と起動しなくなってしまった。最初はリカバリーモードであれこれ試したんだけど技術力の無さから結局解決しなかったので、結局OSを初期化して環境構築をし直す決断をしました。

ところが、メモはある程度残していたものの元と全く同じ環境に戻せなかった。こういうのは今時のDevOpsとかそういうので解決するべき問題なのじゃないのかと思って調べたらPuppetChefAnsibleあたりがよく使われているようで、その中で一番簡単そうに思えたAnsibleを使って構築しようと決めました。

というわけで、まずはAnsibleを使う前にVagrantGMOクラウドVPSと同じUbuntu 12.04を入れるところからやってみたいと思います。

VirtualBoxVagrantを入れる

公式サイトから落として入れるだけ。

Ubuntu 12.04のBoxを入れる

$ vagrant box add ubuntu-12.04-x64 http://files.vagrantup.com/precise64.box
==> box: Adding box 'ubuntu-12.04-x64' (v0) for provider:
box: Downloading: http://files.vagrantup.com/precise64.box
==> box: Successfully added box 'ubuntu-12.04-x64' (v0) for 'virtualbox'!

GMOクラウドVPSが12.04しか対応していないので、古いけど仕方ない。

Ubuntu 12.04のインスタンスを作る

$ vagrant init ubuntu-12.04-x64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

$ vagrant up
...
==> default: Mounting shared folders...
    default: /vagrant => /Users/hentai-kun/blog/vagrant
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant

なんか赤いメッセージが出てきた。

$ vagrant status
Current machine states:

default                   running (virtualbox)

起動はしているようだ。

$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04 LTS
Release:    12.04
Codename:   precise

ログインもできた。

エラーを解消させる

vboxadd setupをすれば解決すると書いてあったので、やってみる。

$ sudo /etc/init.d/vboxadd setup
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used

$ exit
$ vagrant reload
...
==> default: Mounting shared folders...
    default: /vagrant => /Users/hentai-kun/blog/vagrant
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant

結果は変わらない……

バグだった!

少し深く調べたら、Guest Addition 4.3.10とUbuntuの組み合わせで起こるバグだという情報が書いてあった。

書かれている解決策を試してみる。

$ vagrant ssh

$ sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

$ exit
$ vagrant reload
...
==> default: Mounting shared folders...
    default: /vagrant => /Users/hentai-kun/blog/vagrant
==> default: Checking for host entries

うまくいきました!