VagrantとAnsibleの連携

各ツールの簡易説明

Vagrant

  • テキストファイルで仮想マシンを作成(Vagrantfile)
    • Ruby
  • 仮想マシンのイメージをネット上からDLして利用する
  • Provisionerという機能で作成したマシンに対して処理を行える
    •  BashScript,Ansible,etc...

Ansible

  • テキストファイルでサーバ内の状態を設定(Playbook)
    • YAML形式
  • 冪等性(べきとうせい)を保ちやすい
  • エージェントレス

Provisionerについて

Provisioner ansible

. ├── Vagrantfile └── playbook.yml
Vagrant.configure("2") do | config | config.vm.box = "bento/centos-7.4" config.vm.provision "ansible" do | ansible | ansible.playbook = "playbook.yml" end end
  • 実行したいplaybookを設定
  • inventoryは指定しない場合、Vagrantが自動設定
  • ホストOSにAnsibleが必要

Provisioner ansible_local

. ├── Vagrantfile └── playbook.yml
Vagrant.configure("2") do | config | config.vm.box = "bento/centos-7.4" config.vm.provision "ansible_local" do | ansible | ansible.playbook = "playbook.yml" end end
  • 実行したいplaybookを設定
  • inventoryは指定しない場合、Vagrantが自動設定
  • ゲストOSにAnsibleが必要(自動インストールされる)