vagrant-ansible_inventory 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83e1768274c6bb80d6b1096df968bf2d42e24c89
4
+ data.tar.gz: f2b788fd8bb54cae653b6f5bd3690ceb82874c38
5
+ SHA512:
6
+ metadata.gz: f43d834619a35922859b7371320192596192660bd885ebb97ce4c2a2b4b247db036a10634b97d964c501290f51e17216fd5c9cefb71369b22f3d3acd9d29aeef
7
+ data.tar.gz: 35a1d4c8e2e8763e2e956533ea90441c4b0ab6b22cbdcec167a0de5724b5182ca502ca9dbcc79b501ebaa2ad55283fa6f5e1da76b4f23bb630e52f9c91708372
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', github: 'mitchellh/vagrant'
5
+ end
6
+
7
+ group :plugins do
8
+ gem 'vagrant-ansible_inventory', path: '.'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ignacio Galindo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Vagrant::AnsibleInventory
2
+
3
+ Vagrant plugin for building ansible inventory files.
4
+
5
+ Helps defining and building ansible inventory files programatically via
6
+ configuration and command modules.
7
+
8
+ ## Installation
9
+
10
+ First execute:
11
+
12
+ $ vagrant plugin install vagrant-ansible_inventory
13
+
14
+
15
+ ## Usage
16
+
17
+ For a vagrant environment already provisioned with a `Vagrantfile` like the following:
18
+
19
+ ```ruby
20
+ Vagrant.configure(2) do |config|
21
+ define_vm = ->(name, box, memory) {
22
+ config.vm.define name do |instance|
23
+ instance.vm.box = box
24
+ instance.vm.hostname = name
25
+ instance.vm.network 'private_network', type: 'dhcp'
26
+ instance.vm.provider :virtualbox do |i|
27
+ i.name = name
28
+ i.memory = memory
29
+ end
30
+ end
31
+ }
32
+
33
+ define_vm.call 'master', 'trusty32', 256
34
+ define_vm.call 'slave-1', 'trusty32', 256
35
+ define_vm.call 'slave-2', 'trusty32', 256
36
+
37
+ config.ansible.groups = {
38
+ 'cluster:children' => ['master', 'slaves'],
39
+ 'slaves' => ['slave-1', 'slave-2'],
40
+ }
41
+ end
42
+ ```
43
+
44
+ Running:
45
+
46
+ $ vagrant ansible inventory
47
+
48
+ Will output something like:
49
+
50
+ # Generated by vagrant-ansible_inventory plugin
51
+
52
+ [master]
53
+ 172.28.128.6 ansible_ssh_user=vagrant ansible_ssh_port=22
54
+ ansible_ssh_key_file=/Users/joiggama/Projects/vagrant-ansible_inventory/.vagrant/machines/master/virtualbox/private_key
55
+
56
+ [slaves]
57
+ slave-1 ansible_ssh_user=vagrant ansible_ssh_host=172.28.128.7
58
+ ansible_ssh_port=22
59
+ ansible_ssh_key_file=/Users/joiggama/Projects/vagrant-ansible_inventory/.vagrant/machines/slave-1/virtualbox/private_key
60
+ slave-2 ansible_ssh_user=vagrant ansible_ssh_host=172.28.128.8
61
+ ansible_ssh_port=22
62
+ ansible_ssh_key_file=/Users/joiggama/Projects/vagrant-ansible_inventory/.vagrant/machines/slave-2/virtualbox/private_key
63
+
64
+ [cluster:children]
65
+ master
66
+ slaves
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( https://github.com/joiggama/vagrant-ansible_inventory/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create a new Pull Request
75
+
76
+ ## License
77
+
78
+ [The MIT licence](LICENSE.txt)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Vagrantfile ADDED
@@ -0,0 +1,22 @@
1
+ Vagrant.configure(2) do |config|
2
+ define_vm = ->(name, box, memory) {
3
+ config.vm.define name do |instance|
4
+ instance.vm.box = box
5
+ instance.vm.hostname = name
6
+ instance.vm.network 'private_network', type: 'dhcp'
7
+ instance.vm.provider :virtualbox do |i|
8
+ i.name = name
9
+ i.memory = memory
10
+ end
11
+ end
12
+ }
13
+
14
+ define_vm.call 'master', 'trusty32', 256
15
+ define_vm.call 'slave-1', 'trusty32', 256
16
+ define_vm.call 'slave-2', 'trusty32', 256
17
+
18
+ config.ansible.groups = {
19
+ 'cluster:children' => ['master', 'slaves'],
20
+ 'slaves' => ['slave-1', 'slave-2'],
21
+ }
22
+ end
@@ -0,0 +1,4 @@
1
+ require 'vagrant'
2
+
3
+ require 'vagrant/ansible_inventory/plugin'
4
+ require 'vagrant/ansible_inventory/version'
@@ -0,0 +1,78 @@
1
+ require 'optparse'
2
+
3
+ module VagrantPlugins
4
+ module AnsibleInventory
5
+ module Commands
6
+ class Inventory < Vagrant.plugin(2, :command)
7
+
8
+ def execute
9
+ print build
10
+ end
11
+
12
+ private
13
+
14
+ def build
15
+ inv = {}
16
+
17
+ # Detect meta, explicit and implicit groups
18
+ meta = groups.select{|group| group.include?(':children') }
19
+ exp = groups.reject{|group| meta.include?(group) }
20
+ imp = (nodes.keys - exp.values.flatten)
21
+
22
+ # Assign grouped nodes to inventory
23
+ imp.each{|gname| inv[gname] = nodes[gname] }
24
+ exp.each{|gname, gnodes| inv[gname] = gnodes.map{|n| nodes[n].merge id: n }}
25
+ meta.each{|gname, gnames| inv[gname] = gnames }
26
+
27
+ inv
28
+ end
29
+
30
+ def config
31
+ @config ||= with_target_vms{}.first.config
32
+ end
33
+
34
+ def groups
35
+ @groups ||= config.ansible.groups
36
+ end
37
+
38
+ def nodes
39
+ @nodes ||= with_target_vms{}.each_with_object({}) do |machine, hash|
40
+ raise Vagrant::Errors::SSHNotReady unless machine.ssh_info
41
+ hash[machine.name.to_s] = {
42
+ ssh_user: 'vagrant',
43
+ ssh_host: machine.provider.driver.read_guest_ip(1),
44
+ ssh_port: 22,
45
+ ssh_private_key_file: machine.ssh_info[:private_key_path].first
46
+ }
47
+ end
48
+ end
49
+
50
+ def node_attrs(id, node)
51
+ "#{node.delete(id)} #{node.map{|k| "ansible_#{k[0]}=#{k[1]}"}.join(' ')}"
52
+ end
53
+
54
+ def print(inventory)
55
+ out = "# Generated by vagrant-ansible_inventory plugin\n\n"
56
+
57
+ inventory.each do |entries|
58
+ group_name, children = *entries
59
+ out << "[#{group_name}]\n"
60
+
61
+ if children.kind_of? Hash
62
+ out << "#{node_attrs(:ssh_host, children)}\n"
63
+ else
64
+ children.each do |child|
65
+ out << "#{(child.kind_of?(Hash) ? node_attrs(:id, child) : child)}\n"
66
+ end
67
+ end
68
+
69
+ out << "\n"
70
+ end
71
+
72
+ puts out
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,60 @@
1
+ require 'optparse'
2
+
3
+ module VagrantPlugins
4
+ module AnsibleInventory
5
+ module Commands
6
+ class Root < Vagrant.plugin(2, :command)
7
+
8
+ def self.synopsis
9
+ 'display ansible inventory'
10
+ end
11
+
12
+ def initialize(argv, env)
13
+ super
14
+
15
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
16
+
17
+ @subcommands = Vagrant::Registry.new
18
+
19
+ @subcommands.register(:inventory) do
20
+ require_relative 'inventory'
21
+ Inventory
22
+ end
23
+ end
24
+
25
+ def execute
26
+ if @main_args.include?('-h') || @main_args.include?('--help')
27
+ return help
28
+ end
29
+
30
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
31
+ return help if !command_class || !@sub_command
32
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
33
+
34
+ command_class.new(@sub_args, @env).execute
35
+ end
36
+
37
+ def help
38
+ opts = OptionParser.new do |o|
39
+ o.banner = "Usage: vagrant ansible <subcommand> [<args>]"
40
+ o.separator ""
41
+ o.separator "Available subcommands:"
42
+
43
+ keys = []
44
+ @subcommands.each { |key, value| keys << key.to_s }
45
+
46
+ keys.sort.each do |key|
47
+ o.separator " #{key}"
48
+ end
49
+
50
+ o.separator ""
51
+ o.separator "For help on any individual subcommand run `vagrant ansible <subcommand> -h`"
52
+ end
53
+
54
+ @env.ui.info(opts.help, prefix: false)
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module AnsibleInventory
3
+ module Configs
4
+ class Ansible < Vagrant.plugin(2, :config)
5
+
6
+ attr_accessor :groups
7
+
8
+ def initialize
9
+ @groups = UNSET_VALUE
10
+ end
11
+
12
+ def finalize!
13
+ @groups = 0 if @groups == UNSET_VALUE
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module AnsibleInventory
3
+ class Plugin < Vagrant.plugin(2)
4
+
5
+ name 'ansible inventory'
6
+
7
+ config 'ansible' do
8
+ require_relative 'configs/ansible'
9
+ Configs::Ansible
10
+ end
11
+
12
+ command 'ansible' do
13
+ require_relative 'commands/root'
14
+ Commands::Root
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module AnsibleInventory
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'vagrant/ansible_inventory/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'vagrant-ansible_inventory'
7
+ spec.version = VagrantPlugins::AnsibleInventory::VERSION
8
+ spec.authors = ['Ignacio Galindo']
9
+ spec.email = ['joiggama@gmail.com']
10
+ spec.summary = %q{Vagrant plugin for building ansible inventory files.}
11
+ spec.description = %{
12
+ Helps defining and building ansible inventory files
13
+ programatically via configuration and command modules.
14
+ }.strip
15
+ spec.homepage = 'https://github.com/joiggama/vagrant-ansible_inventory'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ansible_inventory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ignacio Galindo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: |-
42
+ Helps defining and building ansible inventory files
43
+ programatically via configuration and command modules.
44
+ email:
45
+ - joiggama@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - Vagrantfile
56
+ - lib/vagrant/ansible_inventory.rb
57
+ - lib/vagrant/ansible_inventory/commands/inventory.rb
58
+ - lib/vagrant/ansible_inventory/commands/root.rb
59
+ - lib/vagrant/ansible_inventory/configs/ansible.rb
60
+ - lib/vagrant/ansible_inventory/plugin.rb
61
+ - lib/vagrant/ansible_inventory/version.rb
62
+ - vagrant-ansible_inventory.gemspec
63
+ homepage: https://github.com/joiggama/vagrant-ansible_inventory
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.5
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Vagrant plugin for building ansible inventory files.
87
+ test_files: []