Skip to content

joiggama/vagrant-ansible_inventory

Repository files navigation

Vagrant::AnsibleInventory

Join the chat at https://gitter.im/joiggama/vagrant-ansible_inventory

Vagrant plugin for building ansible inventory files.

Helps defining and building ansible inventory files programatically via configuration and command modules.

Installation

First execute:

$ vagrant plugin install vagrant-ansible_inventory

Usage

For a vagrant environment already provisioned with a Vagrantfile like the following:

Vagrant.configure(2) do |config|
  define_vm = ->(name, box, memory) {
    config.vm.define name do |instance|
      instance.vm.box      = box
      instance.vm.hostname = name
      instance.vm.network 'private_network', type: 'dhcp'
      instance.vm.provider :virtualbox do |i|
        i.name   = name
        i.memory = memory
      end
    end
  }

  define_vm.call 'master',  'trusty32', 256
  define_vm.call 'slave-1', 'trusty32', 256
  define_vm.call 'slave-2', 'trusty32', 256

  config.ansible.groups = {
    'cluster:children' => ['master', 'slaves'],
    'slaves'           => ['slave-1', 'slave-2'],
  }
end

Running:

$ vagrant ansible inventory

Will output something like:

# Generated by vagrant-ansible_inventory plugin

[master]
master ansible_ssh_user=vagrant ansible_ssh_host=172.28.128.6 ansible_ssh_port=22
ansible_ssh_private_key_file=/Users/joiggama/Projects/vagrant-ansible_inventory/.vagrant/machines/master/virtualbox/private_key

[slaves]
slave-1 ansible_ssh_user=vagrant ansible_ssh_host=172.28.128.7
ansible_ssh_port=22
ansible_ssh_private_key_file=/Users/joiggama/Projects/vagrant-ansible_inventory/.vagrant/machines/slave-1/virtualbox/private_key
slave-2 ansible_ssh_user=vagrant ansible_ssh_host=172.28.128.8
ansible_ssh_port=22
ansible_ssh_private_key_file=/Users/joiggama/Projects/vagrant-ansible_inventory/.vagrant/machines/slave-2/virtualbox/private_key

[cluster:children]
master
slaves

Contributing

  1. Fork it ( https://github.com/joiggama/vagrant-ansible_inventory/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

The MIT licence

About

Vagrant plugin for building ansible inventory files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages