vai 0.9

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19c7148612de75a8de34d2c202730048942bb20d
4
+ data.tar.gz: a63c494ac5a63f8bff4cb1d87fae8586d9e0469c
5
+ SHA512:
6
+ metadata.gz: 699d6cf31a454f8008b1b1535d2895cef9a1926606b28271d96ebab8b2f1700fa13589e3dda28e51af718ff0cbdd4a4b8f9111c803c7efc1c5be8fa492e302ca
7
+ data.tar.gz: 10aadc8402f4efff09faff787beb3932ef47ec7b6253054eacc38db615aeac4073b6e5e7dc16e8359201d183e0962c76b55ee781126fd49af44377a8ac74eb15
@@ -0,0 +1,16 @@
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
15
+ test/.vagrant/*
16
+ test/vagrant_ansible_inventory
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Can't use `gemspec` to pull in dependencies, because the vai gem needs
4
+ # to be in the :plugins group for Vagrant to detect and load it in development
5
+ #gemspec
6
+
7
+ group :development do
8
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
9
+ end
10
+
11
+ group :plugins do
12
+ gemspec
13
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Matthew Miller
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.
@@ -0,0 +1,29 @@
1
+ # Vai
2
+
3
+ A Vagrant provisioning plugin to output a usable Ansible inventory to use outside Vagrant.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ vagrant plugin install vai
9
+ ```
10
+
11
+ ## Usage
12
+ Add something like this to your vagrant file
13
+ ```ruby
14
+ config.vm.provision :vai do |ansible|
15
+ ansible.inventory_dir='path/to/output/inventory/'
16
+ #optional
17
+ ansible.groups = {
18
+ 'group1' => ['box1','box2'],
19
+ 'parentGroup1:children' => ['group1']
20
+ }
21
+ end
22
+ ```
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/MatthewMi11er/vai/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'The Vagrant vai provisioner must be run within Vagrant.'
5
+ end
6
+
7
+ module Vai
8
+ # nothing to do here
9
+ end
10
+
11
+ require_relative "vai/version"
12
+ require_relative 'vai/plugin'
@@ -0,0 +1,28 @@
1
+ module VagrantPlugins
2
+ module Vai
3
+ class Config < Vagrant.plugin("2", :config)
4
+ attr_accessor :inventory_dir
5
+ attr_accessor :groups
6
+
7
+ def initialize
8
+ @inventory_dir = UNSET_VALUE
9
+ @groups = UNSET_VALUE
10
+ end
11
+
12
+ def finalize!
13
+ @inventory_dir = nil if @inventory_dir == UNSET_VALUE
14
+ @groups = {} if @groups == UNSET_VALUE
15
+ end
16
+
17
+ def validate(machine)
18
+ errors = _detected_errors
19
+
20
+ if !inventory_dir
21
+ errors << "inventory_dir not specified."
22
+ end
23
+ { "ansible inventory provisioner" => errors }
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,21 @@
1
+ require "vagrant"
2
+ module VagrantPlugins
3
+ module Vai
4
+ class Plugin < Vagrant.plugin("2")
5
+ name "vai"
6
+ description <<-DESC
7
+ Provides support for auto generating an ansible inventory file
8
+ DESC
9
+
10
+ config(:vai, :provisioner) do
11
+ require File.expand_path("../config", __FILE__)
12
+ Config
13
+ end
14
+
15
+ provisioner(:vai) do
16
+ require File.expand_path("../provisioner", __FILE__)
17
+ Provisioner
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,84 @@
1
+ require "vagrant/util/platform"
2
+ module VagrantPlugins
3
+ module Vai
4
+ class Provisioner < Vagrant.plugin("2", :provisioner)
5
+
6
+ def initialize(machine, config)
7
+ super
8
+ @logger = Log4r::Logger.new("vagrant::provisioners::ansible")
9
+ end
10
+ def provision
11
+ @machine.ui.info("Inventory sucessfully written to #{setup_inventory_file()}")
12
+ end
13
+
14
+ protected
15
+ # Auto-generate "safe" inventory file based on Vagrantfile,
16
+ def setup_inventory_file
17
+ #options << "--sudo" if config.sudo
18
+ #options << "--sudo-user=#{config.sudo_user}" if config.sudo_user
19
+ #"ANSIBLE_HOST_KEY_CHECKING" => "#{config.host_key_checking}",
20
+
21
+ # Managed machines
22
+ inventory_machines = {}
23
+ generated_inventory_dir = Pathname.new(config.inventory_dir)
24
+ FileUtils.mkdir_p(generated_inventory_dir) unless File.directory?(generated_inventory_dir)
25
+ generated_inventory_file = generated_inventory_dir.join('vagrant_ansible_inventory')
26
+ generated_inventory_file.open('w') do |file|
27
+ file.write("# Generated by Vagrant\n\n")
28
+
29
+ @machine.env.active_machines.each do |am|
30
+ begin
31
+ m = @machine.env.machine(*am)
32
+ m_ssh_info = m.ssh_info
33
+ if !m_ssh_info.nil?
34
+ file.write("#{m.name} ansible_ssh_host=#{m_ssh_info[:host]} ansible_ssh_port=#{m_ssh_info[:port]} "\
35
+ "ansible_ssh_private_key_file=#{m_ssh_info[:private_key_path][0]} ansible_ssh_user=#{m_ssh_info[:username]}\n")
36
+ inventory_machines[m.name] = m
37
+ else
38
+ @logger.error("Auto-generated inventory: Impossible to get SSH information for machine '#{m.name} (#{m.provider_name})'. This machine should be recreated.")
39
+ # Let a note about this missing machine
40
+ file.write("# MISSING: '#{m.name}' machine was probably removed without using Vagrant. This machine should be recreated.\n")
41
+ end
42
+ rescue Vagrant::Errors::MachineNotFound => e
43
+ @logger.info("Auto-generated inventory: Skip machine '#{am[0]} (#{am[1]})', which is not configured for this Vagrant environment.")
44
+ end
45
+ end
46
+
47
+ # Write out groups information.
48
+ # All defined groups will be included, but only supported
49
+ # machines and defined child groups will be included.
50
+ # Group variables are intentionally skipped.
51
+ groups_of_groups = {}
52
+ defined_groups = []
53
+
54
+ config.groups.each_pair do |gname, gmembers|
55
+ # Require that gmembers be an array
56
+ # (easier to be tolerant and avoid error management of few value)
57
+ gmembers = [gmembers] if !gmembers.is_a?(Array)
58
+
59
+ if gname.end_with?(":children")
60
+ groups_of_groups[gname] = gmembers
61
+ defined_groups << gname.sub(/:children$/, '')
62
+ elsif !gname.include?(':vars')
63
+ defined_groups << gname
64
+ file.write("\n[#{gname}]\n")
65
+ gmembers.each do |gm|
66
+ file.write("#{gm}\n") if inventory_machines.include?(gm.to_sym)
67
+ end
68
+ end
69
+ end
70
+
71
+ defined_groups.uniq!
72
+ groups_of_groups.each_pair do |gname, gmembers|
73
+ file.write("\n[#{gname}]\n")
74
+ gmembers.each do |gm|
75
+ file.write("#{gm}\n") if defined_groups.include?(gm)
76
+ end
77
+ end
78
+ end
79
+ return generated_inventory_file.to_s
80
+ end
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Vai
3
+ VERSION = "0.9"
4
+ end
5
+ end
@@ -0,0 +1,125 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ # All Vagrant configuration is done here. The most common configuration
9
+ # options are documented and commented below. For a complete reference,
10
+ # please see the online documentation at vagrantup.com.
11
+
12
+ # Every Vagrant virtual environment requires a box to build off of.
13
+ config.vm.box = "ubuntu/trusty64"
14
+ config.vm.provision :vai do |ansible|
15
+ ansible.inventory_dir='./'
16
+ end
17
+
18
+ # Disable automatic box update checking. If you disable this, then
19
+ # boxes will only be checked for updates when the user runs
20
+ # `vagrant box outdated`. This is not recommended.
21
+ # config.vm.box_check_update = false
22
+
23
+ # Create a forwarded port mapping which allows access to a specific port
24
+ # within the machine from a port on the host machine. In the example below,
25
+ # accessing "localhost:8080" will access port 80 on the guest machine.
26
+ # config.vm.network "forwarded_port", guest: 80, host: 8080
27
+
28
+ # Create a private network, which allows host-only access to the machine
29
+ # using a specific IP.
30
+ # config.vm.network "private_network", ip: "192.168.33.10"
31
+
32
+ # Create a public network, which generally matched to bridged network.
33
+ # Bridged networks make the machine appear as another physical device on
34
+ # your network.
35
+ # config.vm.network "public_network"
36
+
37
+ # If true, then any SSH connections made will enable agent forwarding.
38
+ # Default value: false
39
+ # config.ssh.forward_agent = true
40
+
41
+ # Share an additional folder to the guest VM. The first argument is
42
+ # the path on the host to the actual folder. The second argument is
43
+ # the path on the guest to mount the folder. And the optional third
44
+ # argument is a set of non-required options.
45
+ # config.vm.synced_folder "../data", "/vagrant_data"
46
+
47
+ # Provider-specific configuration so you can fine-tune various
48
+ # backing providers for Vagrant. These expose provider-specific options.
49
+ # Example for VirtualBox:
50
+ #
51
+ # config.vm.provider "virtualbox" do |vb|
52
+ # # Don't boot with headless mode
53
+ # vb.gui = true
54
+ #
55
+ # # Use VBoxManage to customize the VM. For example to change memory:
56
+ # vb.customize ["modifyvm", :id, "--memory", "1024"]
57
+ # end
58
+ #
59
+ # View the documentation for the provider you're using for more
60
+ # information on available options.
61
+
62
+ # Enable provisioning with CFEngine. CFEngine Community packages are
63
+ # automatically installed. For example, configure the host as a
64
+ # policy server and optionally a policy file to run:
65
+ #
66
+ # config.vm.provision "cfengine" do |cf|
67
+ # cf.am_policy_hub = true
68
+ # # cf.run_file = "motd.cf"
69
+ # end
70
+ #
71
+ # You can also configure and bootstrap a client to an existing
72
+ # policy server:
73
+ #
74
+ # config.vm.provision "cfengine" do |cf|
75
+ # cf.policy_server_address = "10.0.2.15"
76
+ # end
77
+
78
+ # Enable provisioning with Puppet stand alone. Puppet manifests
79
+ # are contained in a directory path relative to this Vagrantfile.
80
+ # You will need to create the manifests directory and a manifest in
81
+ # the file default.pp in the manifests_path directory.
82
+ #
83
+ # config.vm.provision "puppet" do |puppet|
84
+ # puppet.manifests_path = "manifests"
85
+ # puppet.manifest_file = "default.pp"
86
+ # end
87
+
88
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
89
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
90
+ # some recipes and/or roles.
91
+ #
92
+ # config.vm.provision "chef_solo" do |chef|
93
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
94
+ # chef.roles_path = "../my-recipes/roles"
95
+ # chef.data_bags_path = "../my-recipes/data_bags"
96
+ # chef.add_recipe "mysql"
97
+ # chef.add_role "web"
98
+ #
99
+ # # You may also specify custom JSON attributes:
100
+ # chef.json = { mysql_password: "foo" }
101
+ # end
102
+
103
+ # Enable provisioning with chef server, specifying the chef server URL,
104
+ # and the path to the validation key (relative to this Vagrantfile).
105
+ #
106
+ # The Opscode Platform uses HTTPS. Substitute your organization for
107
+ # ORGNAME in the URL and validation key.
108
+ #
109
+ # If you have your own Chef Server, use the appropriate URL, which may be
110
+ # HTTP instead of HTTPS depending on your configuration. Also change the
111
+ # validation key to validation.pem.
112
+ #
113
+ # config.vm.provision "chef_client" do |chef|
114
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
115
+ # chef.validation_key_path = "ORGNAME-validator.pem"
116
+ # end
117
+ #
118
+ # If you're using the Opscode platform, your validator client is
119
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
120
+ #
121
+ # If you have your own Chef Server, the default validation client name is
122
+ # chef-validator, unless you changed the configuration.
123
+ #
124
+ # chef.validation_client_name = "ORGNAME-validator"
125
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vai/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vai"
8
+ spec.version = VagrantPlugins::Vai::VERSION
9
+ spec.authors = ["Matthew Miller"]
10
+ spec.email = ["matthew@mi11er.net"]
11
+ spec.summary = %q{A Vagrant provisioning plugin to output a usable Ansible inventory to use outside Vagrant.}
12
+ #spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vai
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.9'
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Miller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-24 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
+ email:
43
+ - matthew@mi11er.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/vai.rb
54
+ - lib/vai/config.rb
55
+ - lib/vai/plugin.rb
56
+ - lib/vai/provisioner.rb
57
+ - lib/vai/version.rb
58
+ - test/Vagrantfile
59
+ - vai.gemspec
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.5
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A Vagrant provisioning plugin to output a usable Ansible inventory to use
84
+ outside Vagrant.
85
+ test_files:
86
+ - test/Vagrantfile