I have a multi-machine environment (vagrant, virtualbox, ansible). When the provisioner step runs, only the first machine is actually updated - the subsequent machines show ‘ok’ and do not get the ansible tasks run. How can I ensure that as each host comes up that it gets provisioned – or even, wait to run provisioning till all machines are up?
My Vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.7.0"
IMAGE_NAME = "minimal/xenial64"
boxes = [
{ :name => "test1", :ip => "172.31.254.10" },
{ :name => "test2", :ip => "172.31.254.11" },
{ :name => "test3", :ip => "172.31.254.12" },
{ :name => "test4", :ip => "172.31.254.13" },
{ :name => "test5", :ip => "172.31.254.14" },
{ :name => "test6", :ip => "172.31.254.15" }
]
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.box = IMAGE_NAME
# Virtualbox configuration
config.vm.provider "virtualbox" do |v|
v.memory = 512
v.cpus = 1
end
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.network :private_network, ip: opts[:ip]
config.vm.provision "ansible" do |ansible|
ansible.limit = "all"
ansible.become = true
ansible.verbose = "v"
ansible.playbook = "test_lab.yml"
end
end
end
end
and the very simple ansible playbook (just adds entries to /etc/hosts right now)
---
- name: Set up local dev environment using vagrant and ansible
hosts: all
become: yes
gather_facts: no
tasks:
- name: change /etc/hosts
lineinfile:
path: '/etc/hosts'
line: "{{ item.line }}"
state: present
backup: yes
loop:
- { regexp: '^172.31.254.10', line: '172.31.254.10 test1' }
- { regexp: '^172.31.254.11', line: '172.31.254.11 test2' }
- { regexp: '^172.31.254.12', line: '172.31.254.12 test3' }
- { regexp: '^172.31.254.13', line: '172.31.254.13 test4' }
- { regexp: '^172.31.254.14', line: '172.31.254.14 test5' }
- { regexp: '^172.31.254.15', line: '172.31.254.15 test6' }