読者です 読者をやめる 読者になる 読者になる

はやさがたりない。

へっぽこぷろぐらまのメモログ

ansibleでVagrantをプロビジョニング

前回のsample.ymlhostをVagrantfileと同じ場所におく

Vagrantfileにansibleのプロビジョニング設定を追加。

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "centos6.5"
  config.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box" 

  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "sample.yml"
    ansible.inventory_path = "hosts"
    ansible.limit = 'sample'
  end
end

これで完了っと。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos6.5'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1402233334423_6039
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/akira/vagrant/ansible/vagrant
==> default: Running provisioner: ansible...
 _______________ 
< PLAY [sample] >
 --------------- 
 \     /\  ___  /\
  \   // \/   \/ \\
     ((    O O    ))
      \\ /     \ //
       \/  | |  \/ 
        |  | |  |  
        |  | |  |  
        |   o   |  
        | |   | |  
        |m|   |m|  


 _________________ 
< GATHERING FACTS >
 ----------------- 
 \     /\  ___  /\
  \   // \/   \/ \\
     ((    O O    ))
      \\ /     \ //
       \/  | |  \/ 
        |  | |  |  
        |  | |  |  
        |   o   |  
        | |   | |  
        |m|   |m|  


ok: [192.168.33.10]
 __________________________________ 
< TASK: be sure httpd is installed >
 ---------------------------------- 
 \     /\  ___  /\
  \   // \/   \/ \\
     ((    O O    ))
      \\ /     \ //
       \/  | |  \/ 
        |  | |  |  
        |  | |  |  
        |   o   |  
        | |   | |  
        |m|   |m|  


changed: [192.168.33.10]
 ____________________________________________ 
< TASK: be sure httpd is running and enabled >
 -------------------------------------------- 
 \     /\  ___  /\
  \   // \/   \/ \\
     ((    O O    ))
      \\ /     \ //
       \/  | |  \/ 
        |  | |  |  
        |  | |  |  
        |   o   |  
        | |   | |  
        |m|   |m|  


changed: [192.168.33.10]
 ____________ 
< PLAY RECAP >
 ------------ 
 \     /\  ___  /\
  \   // \/   \/ \\
     ((    O O    ))
      \\ /     \ //
       \/  | |  \/ 
        |  | |  |  
        |  | |  |  
        |   o   |  
        | |   | |  
        |m|   |m|  


192.168.33.10              : ok=3    changed=2    unreachable=0    failed=0   

完了後のものはここ