I'm trying to create multi-machine environment in Vagrant using Ansible as provisioner.
My Vagrantfile looks like next:
Vagrant.configure("2") do |config|
config.vm.provision "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "main.yml"
ansible.inventory_path = "staging"
ansible.verbose = "-vvvv"
end
config.vm.define "machine1" do |machine1|
machine1.vm.box = "ubuntu/trusty64"
machine1.vm.network "private_network", ip:"192.168.77.10"
machine1.vm.hostname = "machine1"
machine1.vm.provider :virtualbox do |vb|
vb.name = "machine1"
end
end
config.vm.define "machine2" do |machine2|
machine2.vm.box = "ubuntu/trusty64"
machine2.vm.network "private_network", ip:"192.168.77.11"
machine2.vm.hostname = "machine2"
machine2.vm.provider :virtualbox do |vb|
vb.name = "machine2"
end
end
config.vm.define "machine3" do |machine3|
machine3.vm.box = "ubuntu/trusty64"
machine3.vm.network "private_network", ip:"192.168.77.12"
machine3.vm.hostname = "machine3"
machine3.vm.provider :virtualbox do |vb|
vb.name = "machine3"
end
end
end
Inventory:
[AppServers]
192.168.77.10
192.168.77.11
192.168.77.12
[WebServers]
192.168.77.11
192.168.77.12
[WebLoadBalancers]
192.168.77.10
[SlaveDbServers]
192.168.77.10
192.168.77.12
[MasterDbServers]
192.168.77.11
[DbLoadBalancers]
192.168.77.11
main.yml:
- hosts: all
roles:
- Common
- ConsulServer
- ConsulAgent
- hosts: WebServers
roles:
- WebServer
- hosts: WebLoadBalancers
roles:
- LoadBalancer
- hosts: MasterDbServers
roles:
- DbServer
I want to get 3 machines. All of them have to contain common soft(Consul servers and agents, vim etc). And some additional - own for each machine. But once i'm running "vagrant up"
only first machine created, provisioner runs, fails because other 2 not created.
Is it possible to run provisioner after all machines created? Or my approach is incorrect and i should perform this in other way?
Thank you for your time.