vagrant-bolt 0.1.0

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 (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +124 -0
  5. data/.travis.yml +28 -0
  6. data/.yardopts +1 -0
  7. data/Gemfile +37 -0
  8. data/LICENSE +12 -0
  9. data/Puppetfile +7 -0
  10. data/README.md +431 -0
  11. data/Rakefile +19 -0
  12. data/Vagrantfile +47 -0
  13. data/acceptance/artifacts/.keep +0 -0
  14. data/acceptance/components/bolt_spec.rb +98 -0
  15. data/acceptance/skeletons/advanced/Vagrantfile +26 -0
  16. data/acceptance/skeletons/base/Vagrantfile +11 -0
  17. data/acceptance/skeletons/base/modules/facts/CHANGELOG.md +26 -0
  18. data/acceptance/skeletons/base/modules/facts/CONTRIBUTING.md +279 -0
  19. data/acceptance/skeletons/base/modules/facts/Gemfile +98 -0
  20. data/acceptance/skeletons/base/modules/facts/LICENSE +201 -0
  21. data/acceptance/skeletons/base/modules/facts/README.md +45 -0
  22. data/acceptance/skeletons/base/modules/facts/Rakefile +8 -0
  23. data/acceptance/skeletons/base/modules/facts/checksums.json +42 -0
  24. data/acceptance/skeletons/base/modules/facts/lib/puppet/functions/facts/group_by.rb +14 -0
  25. data/acceptance/skeletons/base/modules/facts/metadata.json +62 -0
  26. data/acceptance/skeletons/base/modules/facts/plans/info.pp +16 -0
  27. data/acceptance/skeletons/base/modules/facts/plans/init.pp +13 -0
  28. data/acceptance/skeletons/base/modules/facts/tasks/bash.json +5 -0
  29. data/acceptance/skeletons/base/modules/facts/tasks/bash.sh +93 -0
  30. data/acceptance/skeletons/base/modules/facts/tasks/init.json +10 -0
  31. data/acceptance/skeletons/base/modules/facts/tasks/powershell.json +4 -0
  32. data/acceptance/skeletons/base/modules/facts/tasks/powershell.ps1 +56 -0
  33. data/acceptance/skeletons/base/modules/facts/tasks/ruby.json +4 -0
  34. data/acceptance/skeletons/base/modules/facts/tasks/ruby.rb +40 -0
  35. data/acceptance/skeletons/provisioner/Vagrantfile +19 -0
  36. data/acceptance/skeletons/trigger/Vagrantfile +22 -0
  37. data/acceptance/vagrant-spec.config.rb +22 -0
  38. data/lib/vagrant-bolt.rb +57 -0
  39. data/lib/vagrant-bolt/command.rb +65 -0
  40. data/lib/vagrant-bolt/config.rb +6 -0
  41. data/lib/vagrant-bolt/config/bolt.rb +135 -0
  42. data/lib/vagrant-bolt/config/global.rb +172 -0
  43. data/lib/vagrant-bolt/config_builder.rb +11 -0
  44. data/lib/vagrant-bolt/config_builder/config.rb +150 -0
  45. data/lib/vagrant-bolt/config_builder/monkey_patches.rb +71 -0
  46. data/lib/vagrant-bolt/config_builder/provisioner.rb +106 -0
  47. data/lib/vagrant-bolt/config_builder/triggers.rb +29 -0
  48. data/lib/vagrant-bolt/plugin.rb +39 -0
  49. data/lib/vagrant-bolt/provisioner.rb +18 -0
  50. data/lib/vagrant-bolt/runner.rb +88 -0
  51. data/lib/vagrant-bolt/util/bolt.rb +139 -0
  52. data/lib/vagrant-bolt/util/config.rb +43 -0
  53. data/lib/vagrant-bolt/util/machine.rb +73 -0
  54. data/lib/vagrant-bolt/version.rb +5 -0
  55. data/spec/spec_helper.rb +12 -0
  56. data/spec/unit/config/bolt_spec.rb +150 -0
  57. data/spec/unit/config/global_spec.rb +95 -0
  58. data/spec/unit/provisioner/bolt_spec.rb +39 -0
  59. data/spec/unit/runner/runner_spec.rb +122 -0
  60. data/spec/unit/util/bolt_spec.rb +148 -0
  61. data/spec/unit/util/config_spec.rb +53 -0
  62. data/spec/unit/vagrant_spec.rb +9 -0
  63. data/tasks/acceptance.rake +45 -0
  64. data/tasks/spec.rake +5 -0
  65. data/templates/locales/en.yml +24 -0
  66. data/vagrant-bolt.gemspec +24 -0
  67. metadata +109 -0
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant-bolt/util/bolt'
5
+ require 'vagrant-bolt/config'
6
+
7
+ describe VagrantBolt::Util::Bolt do
8
+ include VagrantBolt::Util::Bolt
9
+ let(:config) { VagrantBolt::Config::Bolt.new }
10
+ let(:local_data_path) { '/local/data/path' }
11
+ let(:inventory_path) { "#{local_data_path}/bolt_inventory.yaml" }
12
+
13
+ before(:each) do
14
+ config.finalize!
15
+ end
16
+
17
+ context 'generating the inventory file' do
18
+ let(:env) { double 'env' }
19
+ let(:machine) do
20
+ double(
21
+ name: 'machine',
22
+ ssh_info: {
23
+ host: 'machine',
24
+ },
25
+ )
26
+ end
27
+ let(:machine_hash) do
28
+ {
29
+ "alias" => "machine",
30
+ "config" => {
31
+ "ssh" => {
32
+ "host-key-check" => false,
33
+ "port" => "22",
34
+ "user" => "vagrant",
35
+ "password" => "foo",
36
+ "private-key" => "bar",
37
+ "run-as" => "root",
38
+ },
39
+ "transport" => "ssh",
40
+ },
41
+ "name" => "ssh://machine:22",
42
+ "facts" => { 'a' => 'b' },
43
+ "vars" => { 'foo' => 'bar' },
44
+ "features" => ['foo'],
45
+ }
46
+ end
47
+ let(:config_hash) { { 'config' => { 'a' => 'b' } } }
48
+ let(:node_hash) do
49
+ {
50
+ 'nodes' => [machine_hash],
51
+ 'config' => config_hash['config'],
52
+ }
53
+ end
54
+ before(:each) do
55
+ config.password = 'foo'
56
+ config.run_as = 'root'
57
+ config.port = '22'
58
+ config.private_key = 'bar'
59
+ config.host_key_check = false
60
+ config.user = 'vagrant'
61
+ config.facts = { 'a' => 'b' }
62
+ config.features = ['foo']
63
+ config.vars = { 'foo' => 'bar' }
64
+ config.finalize!
65
+ allow(machine).to receive_message_chain("config.bolt.inventory_config").and_return(config.inventory_config)
66
+ allow(machine).to receive_message_chain("config.vm.communicator").and_return(:ssh)
67
+ allow(machine).to receive_message_chain('communicate.ready?').and_return(true)
68
+ allow(env).to receive_message_chain("vagrantfile.config.bolt.inventory_config").and_return(config_hash)
69
+ allow(env).to receive(:active_machines).and_return(['machine'])
70
+ allow(env).to receive(:machine).and_return(machine)
71
+ allow_any_instance_of(VagrantBolt::Util::Machine).to receive(:nodes_in_environment).with(env).and_return([machine])
72
+ allow_any_instance_of(VagrantBolt::Util::Machine).to receive(:running?).with(machine).and_return(true)
73
+ end
74
+
75
+ it 'creates a node group hash' do
76
+ expect(subject.generate_node_hash(machine)).to eq(machine_hash)
77
+ end
78
+
79
+ it 'creates an inventory hash with groups' do
80
+ expect(subject.generate_inventory_hash(env)).to eq(node_hash)
81
+ end
82
+ end
83
+
84
+ context 'create bolt command' do
85
+ before(:each) do
86
+ config.bolt_exe = 'bolt'
87
+ config.command = 'task'
88
+ config.name = 'foo'
89
+ config.finalize!
90
+ end
91
+
92
+ it 'contains the bolt command' do
93
+ config.node_list = 'ssh://test:22'
94
+ config.user = 'user'
95
+ config.finalize!
96
+ expected = "bolt task run 'foo' --user \'user\' --inventoryfile '#{inventory_path}' --nodes \'ssh://test:22\'"
97
+ expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
98
+ end
99
+
100
+ it 'appends args to the end of the command' do
101
+ config.args = 'bar'
102
+ config.finalize!
103
+ expected = "bolt task run 'foo' --inventoryfile '#{inventory_path}' bar"
104
+ expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
105
+ end
106
+
107
+ it 'adds directories to the command' do
108
+ config.modulepath = 'baz'
109
+ config.boltdir = 'foo'
110
+ config.finalize!
111
+ expected = "bolt task run 'foo' --boltdir 'foo' --modulepath 'baz' --inventoryfile '#{inventory_path}'"
112
+ expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
113
+ end
114
+
115
+ it 'adds booleans to the command' do
116
+ config.verbose = true
117
+ config.ssl = false
118
+ config.finalize!
119
+ expected = "bolt task run 'foo' --no-ssl --verbose --inventoryfile '#{inventory_path}'"
120
+ expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
121
+ end
122
+
123
+ it 'adds params to the command' do
124
+ config.params = { 'a' => 'b' }
125
+ config.finalize!
126
+ expected = "bolt task run 'foo' --params '{\"a\":\"b\"}' --inventoryfile '#{inventory_path}'"
127
+ expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
128
+ end
129
+
130
+ it 'adds debug, verbose, and noop when true' do
131
+ config.debug = true
132
+ config.verbose = true
133
+ config.noop = true
134
+ config.finalize!
135
+ expected = "bolt task run 'foo' --verbose --debug --noop --inventoryfile '#{inventory_path}'"
136
+ expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
137
+ end
138
+
139
+ it 'debug, verbose, and noop are omitted when false' do
140
+ config.debug = false
141
+ config.verbose = false
142
+ config.noop = false
143
+ config.finalize!
144
+ expected = "bolt task run 'foo' --inventoryfile '#{inventory_path}'"
145
+ expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant-bolt/util/config'
5
+ require 'vagrant-bolt/config'
6
+
7
+ describe VagrantBolt::Util::Config do
8
+ let(:global) { VagrantBolt::Config::Bolt.new }
9
+ let(:local) { VagrantBolt::Config::Bolt.new }
10
+ let(:local_data_path) { '/local/data/path' }
11
+ let(:inventory_path) { "#{local_data_path}/bolt_inventory.yaml" }
12
+
13
+ before(:each) do
14
+ global.finalize!
15
+ local.finalize!
16
+ end
17
+
18
+ context 'merging local and global configs' do
19
+ it 'uses global if local is unset' do
20
+ global.name = 'foo'
21
+ global.finalize!
22
+ result = subject.merge_config(local, global)
23
+ expect(result.name).to eq('foo')
24
+ end
25
+
26
+ it 'uses local if local and global are both set' do
27
+ global.name = 'foo'
28
+ global.finalize!
29
+ local.name = 'bar'
30
+ local.finalize!
31
+ result = subject.merge_config(local, global)
32
+ expect(result.name).to eq('bar')
33
+ end
34
+
35
+ it 'does not allow nil overrides' do
36
+ global.name = 'foo'
37
+ global.finalize!
38
+ local.name = nil
39
+ local.finalize!
40
+ result = subject.merge_config(local, global)
41
+ expect(result.name).to eq('foo')
42
+ end
43
+
44
+ it 'merges arrays' do
45
+ global.excludes = ['foo']
46
+ global.finalize!
47
+ local.excludes = ['bar']
48
+ local.finalize!
49
+ result = subject.merge_config(local, global)
50
+ expect(result.excludes).to eq(['bar', 'foo'])
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ describe "Vagrant" do
5
+ it "loads with the bolt plugin" do
6
+ env = Vagrant::Environment.new
7
+ expect(env.cli("-h")).to eq(0)
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ namespace :acceptance do
2
+ desc "displays components that can be tested"
3
+ task :components do
4
+ exec("vagrant-spec components --config=acceptance/vagrant-spec.config.rb")
5
+ end
6
+
7
+ task :setup do
8
+ box = 'alpine/alpine64'
9
+ box_version = '3.7.0'
10
+ provider_name = 'virtualbox'
11
+ box_owner, box_name = box.split('/')
12
+ box_path = File.join('acceptance', 'artifacts', "#{provider_name}.box")
13
+ if !File.exist?(box_path)
14
+ $stderr.puts "Downloading guest box #{box}"
15
+ cmd = "curl -Lf -o #{box_path} https://app.vagrantup.com/#{box_owner}/boxes/#{box_name}/versions/#{box_version}/providers/#{provider_name}.box"
16
+ result = system(cmd)
17
+ if !result
18
+ $stderr.puts
19
+ $stderr.puts "ERROR: Failed to download guest box #{guest_box} for #{provider_name}!"
20
+ exit 1
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "runs acceptance tests"
26
+ task :run do
27
+ args = [
28
+ "--config=acceptance/vagrant-spec.config.rb",
29
+ ]
30
+
31
+ if ENV["COMPONENTS"]
32
+ args << "--components=\"#{ENV["COMPONENTS"]}\""
33
+ end
34
+
35
+ command = "vagrant-spec test #{args.join(" ")}"
36
+ puts command
37
+ puts
38
+ exec(command)
39
+ end
40
+ end
41
+
42
+ task :acceptance do
43
+ Rake::Task['acceptance:setup'].invoke
44
+ Rake::Task['acceptance:run'].invoke
45
+ end
@@ -0,0 +1,5 @@
1
+ Bundler::GemHelper.install_tasks
2
+ RSpec::Core::RakeTask.new(:spec) do |s|
3
+ s.pattern = "spec/unit/**/*_spec.rb"
4
+ s.rspec_opts = "--color"
5
+ end
@@ -0,0 +1,24 @@
1
+ ---
2
+ en:
3
+ vagrant-bolt:
4
+ config:
5
+ bolt:
6
+ errors:
7
+ no_task_or_plan: |-
8
+ No name set. A task, plan, or command name must be specified to use the bolt provisioner
9
+ command_not_specified: |-
10
+ No command set. Please specify either "task", "plan", or "command"
11
+ invalid_command: |-
12
+ Type can only be "task", "plan", or "command", not %{command}
13
+ invalid_data_command: |-
14
+ Invalid data command for %{item} must be %{command}
15
+ noop_compatibility: |-
16
+ Noop is not compatible with %{command}. Please use a task.
17
+ provisioner:
18
+ bolt:
19
+ info:
20
+ running_bolt: |-
21
+ Bolt: Running bolt command locally: %{command}
22
+ error:
23
+ dependent_machines_offline: |-
24
+ Bolt: Dependent Machine not online: %{name}
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'date'
4
+ require 'vagrant-bolt/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'vagrant-bolt'
8
+ gem.version = VagrantBolt::VERSION
9
+ gem.date = Date.today.to_s
10
+
11
+ gem.summary = 'Vagrant provisioning with Puppet Bolt'
12
+ gem.description = <<-DESC
13
+ Vagrant provisioning with Puppet Bolt
14
+ DESC
15
+
16
+ gem.authors = ['Jarret Lavallee']
17
+ gem.email = ['jarret.lavallee@gmail.com']
18
+ gem.homepage = 'https://github.com/oscar-stack/vagrant-bolt'
19
+
20
+ gem.files = %x{git ls-files -z}.split("\0")
21
+ gem.require_path = 'lib'
22
+
23
+ gem.license = 'Apache-2.0'
24
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-bolt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jarret Lavallee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " Vagrant provisioning with Puppet Bolt\n"
14
+ email:
15
+ - jarret.lavallee@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - ".travis.yml"
24
+ - ".yardopts"
25
+ - Gemfile
26
+ - LICENSE
27
+ - Puppetfile
28
+ - README.md
29
+ - Rakefile
30
+ - Vagrantfile
31
+ - acceptance/artifacts/.keep
32
+ - acceptance/components/bolt_spec.rb
33
+ - acceptance/skeletons/advanced/Vagrantfile
34
+ - acceptance/skeletons/base/Vagrantfile
35
+ - acceptance/skeletons/base/modules/facts/CHANGELOG.md
36
+ - acceptance/skeletons/base/modules/facts/CONTRIBUTING.md
37
+ - acceptance/skeletons/base/modules/facts/Gemfile
38
+ - acceptance/skeletons/base/modules/facts/LICENSE
39
+ - acceptance/skeletons/base/modules/facts/README.md
40
+ - acceptance/skeletons/base/modules/facts/Rakefile
41
+ - acceptance/skeletons/base/modules/facts/checksums.json
42
+ - acceptance/skeletons/base/modules/facts/lib/puppet/functions/facts/group_by.rb
43
+ - acceptance/skeletons/base/modules/facts/metadata.json
44
+ - acceptance/skeletons/base/modules/facts/plans/info.pp
45
+ - acceptance/skeletons/base/modules/facts/plans/init.pp
46
+ - acceptance/skeletons/base/modules/facts/tasks/bash.json
47
+ - acceptance/skeletons/base/modules/facts/tasks/bash.sh
48
+ - acceptance/skeletons/base/modules/facts/tasks/init.json
49
+ - acceptance/skeletons/base/modules/facts/tasks/powershell.json
50
+ - acceptance/skeletons/base/modules/facts/tasks/powershell.ps1
51
+ - acceptance/skeletons/base/modules/facts/tasks/ruby.json
52
+ - acceptance/skeletons/base/modules/facts/tasks/ruby.rb
53
+ - acceptance/skeletons/provisioner/Vagrantfile
54
+ - acceptance/skeletons/trigger/Vagrantfile
55
+ - acceptance/vagrant-spec.config.rb
56
+ - lib/vagrant-bolt.rb
57
+ - lib/vagrant-bolt/command.rb
58
+ - lib/vagrant-bolt/config.rb
59
+ - lib/vagrant-bolt/config/bolt.rb
60
+ - lib/vagrant-bolt/config/global.rb
61
+ - lib/vagrant-bolt/config_builder.rb
62
+ - lib/vagrant-bolt/config_builder/config.rb
63
+ - lib/vagrant-bolt/config_builder/monkey_patches.rb
64
+ - lib/vagrant-bolt/config_builder/provisioner.rb
65
+ - lib/vagrant-bolt/config_builder/triggers.rb
66
+ - lib/vagrant-bolt/plugin.rb
67
+ - lib/vagrant-bolt/provisioner.rb
68
+ - lib/vagrant-bolt/runner.rb
69
+ - lib/vagrant-bolt/util/bolt.rb
70
+ - lib/vagrant-bolt/util/config.rb
71
+ - lib/vagrant-bolt/util/machine.rb
72
+ - lib/vagrant-bolt/version.rb
73
+ - spec/spec_helper.rb
74
+ - spec/unit/config/bolt_spec.rb
75
+ - spec/unit/config/global_spec.rb
76
+ - spec/unit/provisioner/bolt_spec.rb
77
+ - spec/unit/runner/runner_spec.rb
78
+ - spec/unit/util/bolt_spec.rb
79
+ - spec/unit/util/config_spec.rb
80
+ - spec/unit/vagrant_spec.rb
81
+ - tasks/acceptance.rake
82
+ - tasks/spec.rake
83
+ - templates/locales/en.yml
84
+ - vagrant-bolt.gemspec
85
+ homepage: https://github.com/oscar-stack/vagrant-bolt
86
+ licenses:
87
+ - Apache-2.0
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.7.6
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Vagrant provisioning with Puppet Bolt
109
+ test_files: []