LoginSignup
29
30

More than 5 years have passed since last update.

vagrant一発でansibleを使って色々初期設定してしまおう(ansible provisioner)

Last updated at Posted at 2016-02-03

はじめに

  • vagrant 1.8.0からansibleのプロビジョナが追加されました。
  • ansibleプロビジョナはvagrantでOS起動するときにansibleが入っていなければゲストOSにインストールしたうえで、指定されたplaybookを実行してくれます。
  • 今回はvagrant起動時にlocaleとtimezoneの設定を行ってくれるものを作りましたが、みんな多分似たようなことやってんだろうと思ってソースは公開しておきました。

使用方法

1.VirtualBoxとVagrant1.8.0以降をインストールする。

  • vagrantのバージョンだけ気を付けましょう。

2.ソースを取得する

  • vagrantfileの中身はお好みに合わせてhost名やIPアドレスなどを編集してください。
  • ちなみに今対応しているOSはCentOS6系と7系です。
git clone https://github.com/uzresk/centos-basic-pre-configured.git

3.起動する

  • timezoneとlocaleの設定を行ったうえでcentosが起動してくれます。便利っすね
vagrant up

ちょっと工夫が必要だった点

  • さらっといくと思ったんですが、うまくいかない点が一点ありました。
  • vagrant up時にansible_localはうまく動いてくれるのですが、起動したOSを停止・削除しようとしたときに以下のエラーが発生し、停止、起動ができなくなってしまいました。
  • https://github.com/mitchellh/vagrant/issues/6740
C:\vagrant\centos-basic-pre-configured>vagrant destroy
    base: Are you sure you want to destroy the 'base' VM? [y/N] y
There are errors in the configuration of this machine. Please fix
the following errors and try again:

ansible local provisioner:
* `playbook` does not exist on the guest: C:/vagrant/site.yml
  • なのでvagrant upする時だけansible_localを呼ぶように変更しました。(恐らく1.8.2では解消される模様です)
  if ARGV[0] == 'up'
    config.vm.provision "ansible_local" do |ansible|
      ansible.playbook = "site.yml"
    end
  end
29
30
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
29
30