Vagrant executing Ansible provisioner twice

92 views
Skip to first unread message

Stephen Knight

unread,
Mar 21, 2016, 2:00:04 AM3/21/16
to Vagrant
Hi All,

I am hoping someone can help, I have a Vagrantfile which uses the Ansible provisioner and it works, everything boots in serial and the installation kicks off via the Ansible Playbook. The issue however is that after successful completion, the Ansible job starts again right back at the beginning. The Vagrantfile is below:

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


Vagrant.require_version ">= 1.8"


Vagrant.configure(2) do |config|
 
  config
.vm.define "supervisor-01" do |supervisor|
        supervisor
.vm.network "private_network", ip: "192.168.9.31"
        supervisor
.vm.box = "centos/7"
        supervisor
.vm.hostname = "supervisor-01"
        supervisor
.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
       
      supervisor
.vm.provider :virtualbox do |vb|
       vb
.customize ["modifyvm", :id, "--macaddress1", "auto"]
       vb
.memory = 1536
       vb
.cpus = 2
       vb
.name = "supervisor-01"
       line
= `VBoxManage list systemproperties | grep "Default machine folder"`
       vb_machine_folder
= line.split(':')[1].strip()
       second_disk
= File.join(vb_machine_folder, vb.name, 'disk_b.vdi')


       vb
.customize ['createhd', '--filename', second_disk, '--format', 'VDI', '--size', 6 * 1024]
       vb
.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', second_disk]
   
end
   
end
   
  config
.vm.define "controller-01" do |controller1|
        controller1
.vm.network "private_network", ip: "192.168.9.21"
        controller1
.vm.box = "centos/7"
        controller1
.vm.hostname = "controller-01"
        controller1
.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
       
      controller1
.vm.provider :virtualbox do |vb|
       vb
.customize ["modifyvm", :id, "--macaddress1", "auto"]
       vb
.memory = 2048
       vb
.cpus = 1
       vb
.name = "controller-01"
       line
= `VBoxManage list systemproperties | grep "Default machine folder"`
       vb_machine_folder
= line.split(':')[1].strip()
       second_disk
= File.join(vb_machine_folder, vb.name, 'disk_b.vdi')


       vb
.customize ['createhd', '--filename', second_disk, '--format', 'VDI', '--size', 100 * 1024]
       vb
.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', second_disk]
   
end
   
end
   
  config
.vm.define "controller-02" do |controller2|
        controller2
.vm.network "private_network", ip: "192.168.9.22"
        controller2
.vm.box = "centos/7"
        controller2
.vm.hostname = "controller-02"
        controller2
.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
       
      controller2
.vm.provider :virtualbox do |vb|
       vb
.customize ["modifyvm", :id, "--macaddress1", "auto"]
       vb
.memory = 2048
       vb
.cpus = 1
       vb
.name = "controller-02"
       line
= `VBoxManage list systemproperties | grep "Default machine folder"`
       vb_machine_folder
= line.split(':')[1].strip()
       second_disk
= File.join(vb_machine_folder, vb.name, 'disk_b.vdi')


       vb
.customize ['createhd', '--filename', second_disk, '--format', 'VDI', '--size', 100 * 1024]
       vb
.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', second_disk]
   
end
   
end
   
  config
.vm.define "controller-03" do |controller3|
        controller3
.vm.network "private_network", ip: "192.168.9.23"
        controller3
.vm.box = "centos/7"
        controller3
.vm.hostname = "controller-03"
        controller3
.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
       
      controller3
.vm.provider :virtualbox do |vb|
       vb
.customize ["modifyvm", :id, "--macaddress1", "auto"]
       vb
.memory = 2048
       vb
.cpus = 1
       vb
.name = "controller-03"
       line
= `VBoxManage list systemproperties | grep "Default machine folder"`
       vb_machine_folder
= line.split(':')[1].strip()
       second_disk
= File.join(vb_machine_folder, vb.name, 'disk_b.vdi')


       vb
.customize ['createhd', '--filename', second_disk, '--format', 'VDI', '--size', 100 * 1024]
       vb
.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', second_disk]
   
end
   
end
   
    config
.vm.define "slave-01" do |slave1|
        slave1
.vm.network "private_network", ip: "192.168.9.11"
        slave1
.vm.box = "centos/7"
        slave1
.vm.hostname = "slave-01"
        slave1
.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
       
      slave1
.vm.provider :virtualbox do |vb|
       vb
.customize ["modifyvm", :id, "--macaddress1", "auto"]
       vb
.memory = 1024
       vb
.cpus = 1
   
end
   
end


    config
.vm.define "slave-02" do |slave2|
        slave2
.vm.network "private_network", ip: "192.168.9.12"
        slave2
.vm.box = "centos/7"
        slave2
.vm.hostname = "slave-02"
        slave2
.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
       
      slave2
.vm.provider :virtualbox do |vb|
       vb
.customize ["modifyvm", :id, "--macaddress1", "auto"]
       vb
.memory = 1024
       vb
.cpus = 1
   
end
   
end


    config
.vm.define "cicd-01" do |cicd|
        cicd
.vm.network "private_network", ip: "192.168.9.32"
        cicd
.vm.box = "centos/7"
        cicd
.vm.hostname = "cicd-01"
        cicd
.vm.synced_folder ".", "/vagrant", type: "rsync"
        cicd
.vm.synced_folder "/var/tmp", "/var/tmp", type: "rsync"
       
      cicd
.vm.provider :virtualbox do |vb|
       vb
.customize ["modifyvm", :id, "--macaddress1", "auto"]
       vb
.memory = 2048
       vb
.cpus = 2
 cicd
.vm.provision :ansible_local do |ansible|
       ansible
.playbook       = "ansible/vagrant.yml"
       ansible
.install        = true
       ansible
.limit          = "all"
       ansible
.inventory_path = "vagrant/hosts"
       ansible
.sudo = true
       ansible
.extra_vars = { ansible_ssh_user: 'vagrant',
        ansible_ssh_pass
: 'vagrant',
                 ansible_connection
: 'ssh',
                 ansible_ssh_args
: '-o StrictHostKeyChecking=no'}
   
end
   
end
 
end
 
end

Is there any reason why the above file should run the provisioner again? I am completely lost as to why this is happening.

Any help is appreciated.

Thanks 

pixel fairy

unread,
Mar 21, 2016, 1:51:25 PM3/21/16
to Vagrant
can we see the hosts file and playbook?

also, could you make a simplified version to isolate the condition? you might find the problem while making it.
Reply all
Reply to author
Forward
0 new messages