vagrant-ansible_auto 0.1.5 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +172 -0
  5. data/README.md +53 -12
  6. data/Rakefile +9 -7
  7. data/TODO.md +14 -0
  8. data/Vagrantfile +37 -15
  9. data/lib/vagrant/ansible_auto/cap/guest/posix/check_open_port.rb +22 -3
  10. data/lib/vagrant/ansible_auto/cap/guest/posix/executable_installed.rb +10 -2
  11. data/lib/vagrant/ansible_auto/cap/guest/posix/gateway_addresses.rb +8 -23
  12. data/lib/vagrant/ansible_auto/cap/guest/posix/private_key.rb +16 -1
  13. data/lib/vagrant/ansible_auto/cap/guest/posix/public_key.rb +18 -3
  14. data/lib/vagrant/ansible_auto/cap/guest/posix/ssh_server_address.rb +22 -12
  15. data/lib/vagrant/ansible_auto/cap/guest/posix.rb +16 -0
  16. data/lib/vagrant/ansible_auto/command/inventory.rb +37 -11
  17. data/lib/vagrant/ansible_auto/command/root.rb +34 -31
  18. data/lib/vagrant/ansible_auto/config.rb +74 -33
  19. data/lib/vagrant/ansible_auto/errors.rb +30 -1
  20. data/lib/vagrant/ansible_auto/host.rb +123 -34
  21. data/lib/vagrant/ansible_auto/inventory.rb +196 -34
  22. data/lib/vagrant/ansible_auto/plugin.rb +23 -8
  23. data/lib/vagrant/ansible_auto/provisioner.rb +121 -79
  24. data/lib/vagrant/ansible_auto/util/config.rb +61 -0
  25. data/lib/vagrant/ansible_auto/util/hash_with_indifferent_access.rb +58 -0
  26. data/lib/vagrant/ansible_auto/util/keys.rb +49 -0
  27. data/lib/vagrant/ansible_auto/util/shell_quote.rb +24 -0
  28. data/lib/vagrant/ansible_auto/version.rb +2 -1
  29. data/lib/vagrant/ansible_auto.rb +15 -0
  30. data/locales/en.yml +34 -0
  31. data/spec/spec_helper.rb +5 -85
  32. data/spec/support/context.rb +111 -0
  33. data/spec/support/matchers.rb +45 -0
  34. data/spec/unit/vagrant/ansible_auto/config_spec.rb +72 -0
  35. data/spec/unit/vagrant/ansible_auto/host_spec.rb +131 -0
  36. data/spec/unit/vagrant/ansible_auto/inventory_spec.rb +349 -0
  37. data/spec/unit/vagrant/ansible_auto/provisioner_spec.rb +248 -0
  38. data/spec/unit/vagrant/ansible_auto/util/config_spec.rb +63 -0
  39. data/spec/unit/vagrant/ansible_auto/util/keys_spec.rb +66 -0
  40. data/vagrant-ansible_auto.gemspec +6 -4
  41. data/vagrant-spec.config.rb +3 -0
  42. data/yard/extensions.rb +45 -0
  43. metadata +36 -11
  44. data/Vagrantfile2 +0 -4
  45. data/Vagrantfile3 +0 -8
  46. data/Vagrantfile4 +0 -31
  47. data/lib/vagrant/ansible_auto/cap/guest/posix/bash_installed.rb +0 -30
  48. data/lib/vagrant/ansible_auto/util.rb +0 -24
  49. data/spec/vagrant/ansible_auto/host_spec.rb +0 -43
  50. data/spec/vagrant/ansible_auto/inventory_spec.rb +0 -79
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'vagrant/ansible_auto/util/keys'
6
+
7
+ describe VagrantPlugins::AnsibleAuto::Util::Keys do
8
+ include_context 'machine'
9
+
10
+ let(:including_klass) do
11
+ Class.new do
12
+ include VagrantPlugins::AnsibleAuto::Util::Keys
13
+ end
14
+ end
15
+
16
+ let(:including_instance) { including_klass.new }
17
+
18
+ let(:fake_private_key_path) { temporary_file('+-----NOT AN RSA PRIVATE KEY-----+') }
19
+
20
+ describe '#insecure_key_path' do
21
+ it 'returns the path to the Vagrant insecure key' do
22
+ expect(including_instance.insecure_key_path).to be_a Pathname
23
+ end
24
+ end
25
+
26
+ describe '#insecure_key_contents' do
27
+ it 'returns the contents of the Vagrant insecure key' do
28
+ expect(including_instance.insecure_key_contents).to be_a String
29
+ expect(including_instance.insecure_key_contents).to include('BEGIN RSA PRIVATE KEY')
30
+ end
31
+ end
32
+
33
+ describe '#insecure_key?' do
34
+ it 'indicates whether the provided key file contains the Vagrant insecure key' do
35
+ expect(including_instance.insecure_key?(including_instance.insecure_key_path)).to be true
36
+ expect(including_instance.insecure_key?(fake_private_key_path)).to be false
37
+ end
38
+ end
39
+
40
+ describe '#fetch_private_key' do
41
+ context 'given a machine with no private keys configured' do
42
+ before do
43
+ allow(machine).to receive(:ssh_info).and_return(nil)
44
+ allow(machine.config.ssh).to receive(:insert_key).and_return(true)
45
+ end
46
+
47
+ it "returns the machine's default private key" do
48
+ expect(including_instance.fetch_private_key(machine)).to eq(machine.env.default_private_key_path)
49
+ end
50
+ end
51
+
52
+ context 'given a machine with at least one private key configured' do
53
+ let(:private_key_paths) do
54
+ [including_instance.insecure_key_path, fake_private_key_path]
55
+ end
56
+
57
+ before do
58
+ allow(ssh_info).to receive(:fetch).with(:private_key_path, anything).and_return(private_key_paths)
59
+ end
60
+
61
+ it "returns the first of the machine's private keys that is not the Vagrant insecure key" do
62
+ expect(including_instance.fetch_private_key(machine)).to eq(fake_private_key_path)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'vagrant/ansible_auto/version'
@@ -16,17 +17,18 @@ Gem::Specification.new do |spec|
16
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
18
 
18
19
  spec.files = `git ls-files -z`.split("\x0").reject do |file|
19
- file.start_with?('.') or spec.test_files.include?(file)
20
+ file.start_with?('.') || spec.test_files.include?(file)
20
21
  end
21
22
 
22
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
24
  spec.require_paths = ['lib']
24
25
 
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'
26
+ spec.add_development_dependency 'bundler', '~> 1.12.5'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 2.14'
28
29
  spec.add_development_dependency 'simplecov'
29
30
  spec.add_development_dependency 'rubocop'
30
31
  spec.add_development_dependency 'cane'
31
32
  spec.add_development_dependency 'coveralls'
33
+ spec.add_development_dependency 'yard'
32
34
  end
@@ -0,0 +1,3 @@
1
+ Vagrant::Spec::Acceptance.configure do |c|
2
+ c.component_paths << 'spec/acceptance'
3
+ end
@@ -0,0 +1,45 @@
1
+ require 'vagrant'
2
+
3
+ module YARD
4
+ module VagrantPlugins
5
+ # Custom class handler for documenting class inheritance from
6
+ # +Vagrant.plugin+
7
+ class ClassHandler < YARD::Handlers::Ruby::ClassHandler
8
+ private
9
+
10
+ def parse_superclass(superclass)
11
+ return nil unless superclass
12
+
13
+ case superclass.type
14
+ when :call, :command_call
15
+ cname = superclass.namespace.source
16
+ if cname =~ /^Vagrant$/ && superclass.method_name(true) == :plugin
17
+ members = superclass.parameters.map { |m| handle_superclass_parameter(m) }
18
+
19
+ begin
20
+ return Vagrant.plugin(*(members[0..1])).to_s
21
+ end
22
+ end
23
+ end
24
+
25
+ super
26
+ end
27
+
28
+ def handle_superclass_parameter(parameter)
29
+ case parameter
30
+ when TrueClass, FalseClass, NilClass
31
+ parameter
32
+ else
33
+ case parameter.type
34
+ when :symbol_literal
35
+ parameter.source[1..-1].to_sym
36
+ when :int
37
+ parameter.source.to_i
38
+ else
39
+ parameter.source
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-ansible_auto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Galindo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.14.0
47
+ version: '2.14'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.14.0
54
+ version: '2.14'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Helps defining and building ansible inventory files programatically via
112
126
  configuration and command modules.
113
127
  email:
@@ -116,17 +130,16 @@ executables: []
116
130
  extensions: []
117
131
  extra_rdoc_files: []
118
132
  files:
133
+ - CHANGELOG.md
119
134
  - Gemfile
135
+ - Gemfile.lock
120
136
  - LICENSE.md
121
137
  - README.md
122
138
  - Rakefile
123
139
  - TODO.md
124
140
  - Vagrantfile
125
- - Vagrantfile2
126
- - Vagrantfile3
127
- - Vagrantfile4
128
141
  - lib/vagrant/ansible_auto.rb
129
- - lib/vagrant/ansible_auto/cap/guest/posix/bash_installed.rb
142
+ - lib/vagrant/ansible_auto/cap/guest/posix.rb
130
143
  - lib/vagrant/ansible_auto/cap/guest/posix/check_open_port.rb
131
144
  - lib/vagrant/ansible_auto/cap/guest/posix/executable_installed.rb
132
145
  - lib/vagrant/ansible_auto/cap/guest/posix/gateway_addresses.rb
@@ -141,13 +154,25 @@ files:
141
154
  - lib/vagrant/ansible_auto/inventory.rb
142
155
  - lib/vagrant/ansible_auto/plugin.rb
143
156
  - lib/vagrant/ansible_auto/provisioner.rb
144
- - lib/vagrant/ansible_auto/util.rb
157
+ - lib/vagrant/ansible_auto/util/config.rb
158
+ - lib/vagrant/ansible_auto/util/hash_with_indifferent_access.rb
159
+ - lib/vagrant/ansible_auto/util/keys.rb
160
+ - lib/vagrant/ansible_auto/util/shell_quote.rb
145
161
  - lib/vagrant/ansible_auto/version.rb
162
+ - locales/en.yml
146
163
  - playbooks/test.yml
147
164
  - spec/spec_helper.rb
148
- - spec/vagrant/ansible_auto/host_spec.rb
149
- - spec/vagrant/ansible_auto/inventory_spec.rb
165
+ - spec/support/context.rb
166
+ - spec/support/matchers.rb
167
+ - spec/unit/vagrant/ansible_auto/config_spec.rb
168
+ - spec/unit/vagrant/ansible_auto/host_spec.rb
169
+ - spec/unit/vagrant/ansible_auto/inventory_spec.rb
170
+ - spec/unit/vagrant/ansible_auto/provisioner_spec.rb
171
+ - spec/unit/vagrant/ansible_auto/util/config_spec.rb
172
+ - spec/unit/vagrant/ansible_auto/util/keys_spec.rb
150
173
  - vagrant-ansible_auto.gemspec
174
+ - vagrant-spec.config.rb
175
+ - yard/extensions.rb
151
176
  homepage: https://github.com/joiggama/vagrant-ansible_auto
152
177
  licenses:
153
178
  - MIT
data/Vagrantfile2 DELETED
@@ -1,4 +0,0 @@
1
- Vagrant.configure(2) do |config|
2
- config.vm.box = 'ubuntu/trusty64'
3
- config.vm.network :private_network, type: :dhcp
4
- end
data/Vagrantfile3 DELETED
@@ -1,8 +0,0 @@
1
- Vagrant.configure(2) do |config|
2
- config.vm.box = 'trusty64'
3
- config.vm.network :private_network, type: :dhcp
4
-
5
- config.ansible.groups = {
6
- 'ubuntu' => ['default']
7
- }
8
- end
data/Vagrantfile4 DELETED
@@ -1,31 +0,0 @@
1
- Vagrant.configure(2) do |config|
2
- config.vm.box = 'hashicorp/precise64'
3
-
4
- (1..2).each do |i|
5
- name = "ansible-test-worker-#{i}"
6
- config.vm.define name do |target|
7
- end
8
- end
9
-
10
- config.vm.define 'ansible-test-control' do |machine|
11
- machine.vm.provision :ansible_auto do |ansible|
12
- ansible.limit = '*'
13
- ansible.playbook = 'playbooks/test.yml'
14
- end
15
- end
16
-
17
- config.ansible.groups = {
18
- 'control' => %w(ansible-test-control),
19
- 'worker' => %w(ansible-test-worker-1 ansible-test-worker-2),
20
- 'cluster:children' => %w(control worker),
21
- }
22
-
23
- config.ansible.vars = {
24
- 'control' => {
25
- 'role' => 'ansible-control',
26
- },
27
- 'worker' => {
28
- 'role' => 'ansible-worker',
29
- }
30
- }
31
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
- module VagrantPlugins
3
- module AnsibleAuto
4
- module Cap
5
- module Guest
6
- module POSIX
7
- class BashInstalled
8
- class << self
9
- def bash_installed?(machine, version = nil)
10
- machine.communicate.execute(%q(command bash -c 'printf -- "%s\t%s" "$BASH" "$BASH_VERSION"'), error_check: false) do |type, data|
11
- data.chomp!
12
-
13
- # Not sure why, but we always get an empty first line...
14
- next if data.empty?
15
-
16
- if type == :stdout
17
- bash_path, bash_version = *data.split("\t")
18
- return (!bash_path.empty? and (version.nil? or version == bash_version))
19
- end
20
- end
21
-
22
- false
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
- module VagrantPlugins
3
- module AnsibleAuto
4
- module Util
5
- # Adapted from VagrantPlugins::CommunicatorSSH::Communicator#insecure_key?.
6
- # This will test whether +path+ is the Vagrant insecure private key.
7
- #
8
- # @param [String] path
9
- def insecure_key?(path)
10
- return false if path.nil? or !File.file?(path)
11
- @__insecure_key ||= Vagrant.source_root.join('keys/vagrant').read.chomp
12
- File.read(path).chomp == @_insecure_key
13
- end
14
-
15
- def fetch_private_key(machine)
16
- if machine.config.ssh.insert_key && !machine.ssh_info.nil?
17
- machine.ssh_info.fetch(:private_key_path, []).find { |k| !insecure_key?(k) }
18
- else
19
- machine.env.default_private_key_path
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,43 +0,0 @@
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
@@ -1,79 +0,0 @@
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