Skip to content

Instantly share code, notes, and snippets.

@wojtha
Last active April 11, 2017 13:22
Show Gist options
  • Save wojtha/80599ab432ce0ccdbe1fbc13e1951c70 to your computer and use it in GitHub Desktop.
Save wojtha/80599ab432ce0ccdbe1fbc13e1951c70 to your computer and use it in GitHub Desktop.
Using ansibler gem to share Ansible inventory file with Vagrant https://github.com/aisrael/ansibler
web1 ansible_host=192.168.4.11 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/wojtha/.vagrant.d/insecure_private_key'
mongo1 ansible_host=192.168.4.21 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/wojtha/.vagrant.d/insecure_private_key'
redis1 ansible_host=192.168.4.31 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/wojtha/.vagrant.d/insecure_private_key'
[mongo]
mongo1
[redis]
redis1
[web]
web1
Vagrant.configure("2") do |config|
# Base VM OS configuration.
config.vm.box = "geerlingguy/ubuntu1404"
config.vm.synced_folder '.', '/vagrant', disabled: true
config.ssh.insert_key = false
config.vm.provider :virtualbox do |v|
v.memory = 256
v.cpus = 1
v.linked_clone = true
end
unless defined? Ansible::Inventory
fail "Missing `ansibler` plugin. Please run `vagrant plugin install ansibler` and try again"
end
inventory = Ansible::Inventory.read_file('inventories/vagrant')
config.vm.provision "ansible" do |ansible|
ansible.playbook = "configure.yml"
ansible.groups = inventory.groups.each_with_object({}) { |group, acc| acc[group.name] = group.hosts.map(&:name) }
end
inventory.hosts.each do |host|
config.vm.define host.name do |machine|
machine.vm.network :private_network, ip: host.vars[:ansible_host]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment