vagrant-ansible_auto 0.1.5

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.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/LICENSE.md +23 -0
  4. data/README.md +129 -0
  5. data/Rakefile +12 -0
  6. data/TODO.md +8 -0
  7. data/Vagrantfile +23 -0
  8. data/Vagrantfile2 +4 -0
  9. data/Vagrantfile3 +8 -0
  10. data/Vagrantfile4 +31 -0
  11. data/lib/vagrant/ansible_auto/cap/guest/posix/bash_installed.rb +30 -0
  12. data/lib/vagrant/ansible_auto/cap/guest/posix/check_open_port.rb +34 -0
  13. data/lib/vagrant/ansible_auto/cap/guest/posix/executable_installed.rb +20 -0
  14. data/lib/vagrant/ansible_auto/cap/guest/posix/gateway_addresses.rb +62 -0
  15. data/lib/vagrant/ansible_auto/cap/guest/posix/private_key.rb +22 -0
  16. data/lib/vagrant/ansible_auto/cap/guest/posix/public_key.rb +28 -0
  17. data/lib/vagrant/ansible_auto/cap/guest/posix/ssh_server_address.rb +88 -0
  18. data/lib/vagrant/ansible_auto/command/inventory.rb +50 -0
  19. data/lib/vagrant/ansible_auto/command/root.rb +59 -0
  20. data/lib/vagrant/ansible_auto/config.rb +78 -0
  21. data/lib/vagrant/ansible_auto/errors.rb +14 -0
  22. data/lib/vagrant/ansible_auto/host.rb +86 -0
  23. data/lib/vagrant/ansible_auto/inventory.rb +189 -0
  24. data/lib/vagrant/ansible_auto/plugin.rb +74 -0
  25. data/lib/vagrant/ansible_auto/provisioner.rb +181 -0
  26. data/lib/vagrant/ansible_auto/util.rb +24 -0
  27. data/lib/vagrant/ansible_auto/version.rb +6 -0
  28. data/lib/vagrant/ansible_auto.rb +5 -0
  29. data/playbooks/test.yml +4 -0
  30. data/spec/spec_helper.rb +93 -0
  31. data/spec/vagrant/ansible_auto/host_spec.rb +43 -0
  32. data/spec/vagrant/ansible_auto/inventory_spec.rb +79 -0
  33. data/vagrant-ansible_auto.gemspec +32 -0
  34. metadata +175 -0
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+ unless RUBY_ENGINE == 'rbx' # coverage support is broken on rbx
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(formatters)
8
+ SimpleCov.start do
9
+ minimum_coverage 100
10
+ add_group 'Sources', 'lib'
11
+ add_group 'Tests', 'spec'
12
+ end
13
+ end
14
+
15
+ require 'pathname'
16
+
17
+ $LOAD_PATH.unshift((Pathname.new(__FILE__).parent.parent + 'lib').to_s)
18
+
19
+ require 'vagrant/ansible_auto'
20
+
21
+ # We're using an older version of rspec-expectations that doesn't have the
22
+ # `all' matcher.
23
+ RSpec::Matchers.define :all do |expected|
24
+ define_method :index_failed_objects do |actual|
25
+ end
26
+
27
+ def index_failed_objects(actual)
28
+ return enum_for(__method__, actual) unless block_given?
29
+
30
+ @failed_items = []
31
+
32
+ actual.each_with_index do |o, i|
33
+ @failed_items[i] = yield o
34
+ end
35
+
36
+ @failed_items.compact.empty?
37
+ end
38
+
39
+ match_for_should do |actual|
40
+ index_failed_objects(actual) do |item|
41
+ expected.failure_message_for_should unless expected.matches?(item)
42
+ end
43
+ end
44
+
45
+ match_for_should_not do |actual|
46
+ index_failed_objects(actual) do |item|
47
+ expected.failure_message_for_should_not if expected.matches?(item)
48
+ end
49
+ end
50
+
51
+ def failure_message(actual)
52
+ if actual.respond_to?(:each_with_index)
53
+ @failed_items.each_with_index.reject { |f, _i| f.nil? }.map do |f, i|
54
+ "object at index #{i} failed to match: #{f}"
55
+ end.join("\n")
56
+ else
57
+ "provided object is not iterable"
58
+ end
59
+ end
60
+
61
+ failure_message_for_should { |actual| failure_message(actual) }
62
+ failure_message_for_should_not { |actual| failure_message(actual) }
63
+ end
64
+
65
+ shared_context 'machine' do
66
+ let(:machine) { double('machine') }
67
+ let(:state) { double('state') }
68
+ let(:ssh_info) { Hash.new }
69
+
70
+ before do
71
+ machine.stub(ssh_info: ssh_info, state: state)
72
+ machine.stub(name: 'mymachine')
73
+ state.stub(id: :running)
74
+ allow(ssh_info).to receive(:[])
75
+ allow(ssh_info).to receive(:fetch).with(:private_key_path, anything).and_return([])
76
+ end
77
+ end
78
+
79
+ shared_context 'host' do
80
+ require 'vagrant/ansible_auto/host'
81
+
82
+ include_context 'machine'
83
+
84
+ let(:host) { VagrantPlugins::AnsibleAuto::Host.new(machine) }
85
+ end
86
+
87
+ shared_context 'inventory' do
88
+ require 'vagrant/ansible_auto/host'
89
+
90
+ include_context 'machine'
91
+
92
+ let(:inventory) { VagrantPlugins::AnsibleAuto.new }
93
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ require 'vagrant/ansible_auto/host'
5
+
6
+ describe VagrantPlugins::AnsibleAuto::HostMachine do
7
+ include_context 'machine'
8
+
9
+ subject { described_class.new(machine) }
10
+
11
+ describe '#ssh_user' do
12
+ it 'corresponds to machine.ssh_info[:username]' do
13
+ expect(ssh_info).to receive(:[]).with(:username).and_return('me')
14
+ expect(subject.ssh_user).to eq 'me'
15
+ end
16
+ end
17
+
18
+ describe '#ssh_host' do
19
+ it 'corresponds to machine.ssh_info[:host]' do
20
+ expect(ssh_info).to receive(:[]).with(:host).and_return('foo.bar.net')
21
+ expect(subject.ssh_host).to eq 'foo.bar.net'
22
+ end
23
+ end
24
+
25
+ describe '#ssh_port' do
26
+ it 'corresponds to machine.ssh_info[:port]' do
27
+ expect(ssh_info).to receive(:[]).with(:port).and_return(2222)
28
+ expect(subject.ssh_port).to eq 2222
29
+ end
30
+ end
31
+
32
+ describe '#ssh_private_key_file' do
33
+ it 'corresponds to machine.ssh_info[:private_key_path]' do
34
+ expect(ssh_info).to receive(:fetch).with(:private_key_path, anything).and_return(['/path/to/private_key'])
35
+ expect(subject.ssh_private_key_file).to eq '/path/to/private_key'
36
+ end
37
+
38
+ it 'has no default' do
39
+ expect(ssh_info).to receive(:fetch).with(:private_key_path, anything).and_return([])
40
+ expect(subject.ssh_private_key_file).to be_nil
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ require 'vagrant/ansible_auto/inventory'
5
+
6
+ describe VagrantPlugins::AnsibleAuto::Inventory do
7
+ subject { described_class.new }
8
+
9
+ # include_context 'machine'
10
+
11
+ describe '#add_group' do
12
+ it 'adds a list of hosts to the group cache' do
13
+ subject.add_group(:mygroup, 'db', 'bastion', 'firewall')
14
+ subject.groups.tap do |groups|
15
+ expect(groups).to have_key("mygroup")
16
+ expect(groups["mygroup"]).to include('db', 'bastion', 'firewall')
17
+ end
18
+ end
19
+
20
+ it 'appends new hosts to existing groups' do
21
+ subject.add_group(:mygroup, 'db', 'bastion', 'firewall')
22
+ subject.add_group(:mygroup, 'repo')
23
+ subject.groups.tap do |groups|
24
+ expect(groups).to have_key("mygroup")
25
+ expect(groups["mygroup"]).to include('db', 'bastion', 'firewall', 'repo')
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#add_host' do
31
+ include_context 'host'
32
+
33
+ it 'adds a host to the host cache' do
34
+ subject.add_host(host)
35
+ expect(subject.hosts).to include(host)
36
+ end
37
+
38
+ it 'does not allow duplicates' do
39
+ 2.times { subject.add_host(host) }
40
+ expect(subject.hosts).to have(1).items
41
+ end
42
+
43
+ it 'coerces instances of Vagrant::Machine to instances of Host' do
44
+ subject.add_host(machine)
45
+ expect(subject.hosts).to all(be_a(VagrantPlugins::AnsibleAuto::Host))
46
+ end
47
+
48
+ it 'coerces names + hostvars to instances of Host' do
49
+ subject.add_host("mymachine", ansible_ssh_host: 'foo.bar.net')
50
+ end
51
+ end
52
+
53
+ describe '#groups=' do
54
+ it 'returns a hash of sets' do
55
+ expect(subject.groups).to be_a(Hash)
56
+ expect(subject.groups[:foo]).to be_a(Set)
57
+ end
58
+ end
59
+
60
+ describe '#hosts=' do
61
+ it 'returns a set' do
62
+ expect(subject.hosts).to be_a(Set)
63
+ end
64
+ end
65
+
66
+ describe '#vars=' do
67
+ it 'returns a hash of hashes' do
68
+ expect(subject.vars).to be_a(Hash)
69
+ expect(subject.vars[:meh]).to be_a(Hash)
70
+ end
71
+ end
72
+
73
+ describe '#children=' do
74
+ it 'returns a hash of sets' do
75
+ expect(subject.children).to be_a(Hash)
76
+ expect(subject.children[:quux]).to be_a(Set)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant/ansible_auto/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vagrant-ansible_auto'
8
+ spec.version = VagrantPlugins::AnsibleAuto::VERSION
9
+ spec.authors = ['Ignacio Galindo']
10
+ spec.email = ['joiggama@gmail.com']
11
+ spec.summary = 'Vagrant plugin for building ansible inventory files.'
12
+ spec.description = 'Helps defining and building ansible inventory files programatically via configuration and command modules.'
13
+ spec.homepage = 'https://github.com/joiggama/vagrant-ansible_auto'
14
+ spec.license = 'MIT'
15
+
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |file|
19
+ file.start_with?('.') or spec.test_files.include?(file)
20
+ end
21
+
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.12.5'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 2.14.0'
28
+ spec.add_development_dependency 'simplecov'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'cane'
31
+ spec.add_development_dependency 'coveralls'
32
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ansible_auto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Ignacio Galindo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-18 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.12.5
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.12.5
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cane
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Helps defining and building ansible inventory files programatically via
112
+ configuration and command modules.
113
+ email:
114
+ - joiggama@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - Gemfile
120
+ - LICENSE.md
121
+ - README.md
122
+ - Rakefile
123
+ - TODO.md
124
+ - Vagrantfile
125
+ - Vagrantfile2
126
+ - Vagrantfile3
127
+ - Vagrantfile4
128
+ - lib/vagrant/ansible_auto.rb
129
+ - lib/vagrant/ansible_auto/cap/guest/posix/bash_installed.rb
130
+ - lib/vagrant/ansible_auto/cap/guest/posix/check_open_port.rb
131
+ - lib/vagrant/ansible_auto/cap/guest/posix/executable_installed.rb
132
+ - lib/vagrant/ansible_auto/cap/guest/posix/gateway_addresses.rb
133
+ - lib/vagrant/ansible_auto/cap/guest/posix/private_key.rb
134
+ - lib/vagrant/ansible_auto/cap/guest/posix/public_key.rb
135
+ - lib/vagrant/ansible_auto/cap/guest/posix/ssh_server_address.rb
136
+ - lib/vagrant/ansible_auto/command/inventory.rb
137
+ - lib/vagrant/ansible_auto/command/root.rb
138
+ - lib/vagrant/ansible_auto/config.rb
139
+ - lib/vagrant/ansible_auto/errors.rb
140
+ - lib/vagrant/ansible_auto/host.rb
141
+ - lib/vagrant/ansible_auto/inventory.rb
142
+ - lib/vagrant/ansible_auto/plugin.rb
143
+ - lib/vagrant/ansible_auto/provisioner.rb
144
+ - lib/vagrant/ansible_auto/util.rb
145
+ - lib/vagrant/ansible_auto/version.rb
146
+ - playbooks/test.yml
147
+ - spec/spec_helper.rb
148
+ - spec/vagrant/ansible_auto/host_spec.rb
149
+ - spec/vagrant/ansible_auto/inventory_spec.rb
150
+ - vagrant-ansible_auto.gemspec
151
+ homepage: https://github.com/joiggama/vagrant-ansible_auto
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.5.2
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Vagrant plugin for building ansible inventory files.
175
+ test_files: []