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,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantBolt::Config
4
+ require_relative 'config/global'
5
+ require_relative 'config/bolt'
6
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
4
+ # @!attribute [rw] args
5
+ # @return [String] Additional arguments for the bolt command
6
+ attr_accessor :args
7
+
8
+ # @!attribute [rw] name
9
+ # @return [String] The name of task or plan to run
10
+ attr_accessor :name
11
+
12
+ # @!attribute [rw] nodes
13
+ # Note: The `node_list` will override this setting.
14
+ # @return [Array<String, Symbol>, "ALL"] The nodes to run the task or plan on.
15
+ # Valid values are an array of machine names or the string "ALL".
16
+ attr_accessor :nodes
17
+
18
+ # @!attribute [rw] excludes
19
+ # Note: The `node_list` will override this setting.
20
+ # Note: This will be merged with `nodes`, with `excludes` taking precidence.
21
+ # @return [Array<String, Symbol>] The nodes to exclude from running this task or plan on.
22
+ # Valid values are an array of machine names.
23
+ attr_accessor :excludes
24
+
25
+ # @!attribute [rw] node_list
26
+ # This setting overrides `nodes` and needs to be in the `protocol://ipaddress:port` URI format.
27
+ # @return [String] The bolt node list. This defaults to the currnet node.
28
+ attr_accessor :node_list
29
+
30
+ # @!attribute [rw] params
31
+ # @return [Hash] The paramater hash for the task or plan
32
+ attr_accessor :params
33
+
34
+ # @!attribute [rw] command
35
+ # @return [Symbol] Which command bolt should use. task, plan, command
36
+ attr_accessor :command
37
+
38
+ # @!attribute [rw] noop
39
+ # @return [Boolean] If the command should be run with noop. Only valid with tasks and apply.
40
+ attr_accessor :noop
41
+
42
+ def initialize
43
+ super
44
+ @args = UNSET_VALUE
45
+ @name = UNSET_VALUE
46
+ @nodes = []
47
+ @excludes = []
48
+ @node_list = UNSET_VALUE
49
+ @params = UNSET_VALUE
50
+ @command = UNSET_VALUE
51
+ end
52
+
53
+ def finalize!
54
+ @bolt_exe = nil if @bolt_exe == UNSET_VALUE
55
+ @boltdir = nil if @boltdir == UNSET_VALUE
56
+ @host_key_check = nil if @host_key_check == UNSET_VALUE
57
+ @modulepath = nil if @modulepath == UNSET_VALUE
58
+ @port = nil if @port == UNSET_VALUE
59
+ @password = nil if @password == UNSET_VALUE
60
+ @private_key = nil if @private_key == UNSET_VALUE
61
+ @run_as = nil if @run_as == UNSET_VALUE
62
+ @ssl = nil if @ssl == UNSET_VALUE
63
+ @ssl_verify = nil if @ssl_verify == UNSET_VALUE
64
+ @sudo_password = nil if @sudo_password == UNSET_VALUE
65
+ @tmpdir = nil if @tmpdir == UNSET_VALUE
66
+ @user = nil if @user == UNSET_VALUE
67
+ @verbose = nil if @verbose == UNSET_VALUE
68
+ @debug = nil if @debug == UNSET_VALUE
69
+
70
+ @args = nil if @args == UNSET_VALUE
71
+ @name = nil if @name == UNSET_VALUE
72
+ @node_list = nil if @node_list == UNSET_VALUE
73
+ @params = nil if @params == UNSET_VALUE
74
+ @command = nil if @command == UNSET_VALUE
75
+ @noop = nil if @noop == UNSET_VALUE
76
+ end
77
+
78
+ def merge(other)
79
+ super.tap do |result|
80
+ new_excludes = (excludes + other.excludes.dup).flatten.uniq
81
+ result.instance_variable_set(:@excludes, new_excludes.to_a)
82
+ unless nodes.to_s.casecmp("all").zero?
83
+ new_nodes = (nodes + other.nodes.dup).flatten.uniq
84
+ result.instance_variable_set(:@nodes, new_nodes.to_a)
85
+ end
86
+ end
87
+ end
88
+
89
+ def validate(_machine)
90
+ errors = _detected_errors
91
+ errors << I18n.t('vagrant-bolt.config.bolt.errors.invalid_command', command: @command.to_s) if !@command.nil? && !['task', 'plan', 'command'].include?(@command.to_s)
92
+
93
+ if @nodes.nil? || (!(@nodes.is_a? Array) && !@nodes.to_s.casecmp("all").zero?)
94
+ errors << I18n.t('vagrant-bolt.config.bolt.errors.invalid_data_command',
95
+ item: 'nodes',
96
+ command: 'array')
97
+ end
98
+
99
+ if @excludes.nil? || !(@excludes.is_a? Array)
100
+ errors << I18n.t('vagrant-bolt.config.bolt.errors.invalid_data_command',
101
+ item: 'excludes',
102
+ command: 'array')
103
+ end
104
+
105
+ if @command.nil? && !@name.nil?
106
+ errors << I18n.t('vagrant-bolt.config.bolt.errors.command_not_specified')
107
+ elsif !@command.nil? && @name.nil?
108
+ errors << I18n.t('vagrant-bolt.config.bolt.errors.no_task_or_plan')
109
+ end
110
+
111
+ if @command.to_s != 'task' && @noop
112
+ errors << I18n.t('vagrant-bolt.config.bolt.errors.noop_compatibility',
113
+ command: @command)
114
+ end
115
+
116
+ { "Bolt" => errors }
117
+ end
118
+
119
+ # Return a list of settings that are not applicable to the bolt command line options
120
+ # @return [Array<String>] An array of settings to ignore when creating a bolt command
121
+ def blacklist
122
+ [
123
+ 'nodes',
124
+ 'excludes',
125
+ 'node_list',
126
+ 'bolt_exe',
127
+ 'args',
128
+ 'command',
129
+ 'name',
130
+ 'vars',
131
+ 'facts',
132
+ 'features',
133
+ ]
134
+ end
135
+ end
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ class VagrantBolt::Config::Global < Vagrant.plugin('2', :config)
4
+ # @!attribute [rw] bolt_exe
5
+ # @return [String] The full path to the bolt command. If not passed in, the default from PATH will be used.
6
+ attr_accessor :bolt_exe
7
+
8
+ # @!attribute [rw] boltdir
9
+ # @return [String] The bolt working directory. Defaults to `.`
10
+ attr_accessor :boltdir
11
+
12
+ # @!attribute [rw] host_key_check
13
+ # @return [Boolean] If the connection should check the host key on the remote host (linux)
14
+ attr_accessor :host_key_check
15
+
16
+ # @!attribute [rw] modulepath
17
+ # @return [String] The path to the modules. Defaults to `modules`.
18
+ attr_accessor :modulepath
19
+
20
+ # @!attribute [rw] user
21
+ # @return [String] The user to authenticate on the machine.
22
+ attr_accessor :user
23
+
24
+ # @!attribute [rw] password
25
+ # @return [String] The password to authenticate on the machine.
26
+ attr_accessor :password
27
+
28
+ # @!attribute [rw] port
29
+ # @return [String] The port to connect to the machine.
30
+ attr_accessor :port
31
+
32
+ # @!attribute [rw] private_key
33
+ # @return [String] The path of the private_key to authenticate on the machine.
34
+ attr_accessor :private_key
35
+
36
+ # @!attribute [rw] run_as
37
+ # @return [String] User to run as using privilege escalation.
38
+ attr_accessor :run_as
39
+
40
+ # @!attribute [rw] sudo_password
41
+ # @return [String] The password to authenticate sudo on the machine.
42
+ attr_accessor :sudo_password
43
+
44
+ # @!attribute [rw] ssl
45
+ # @return [Boolean] If the connection should use SSL on with WinRM (Windows)
46
+ attr_accessor :ssl
47
+
48
+ # @!attribute [rw] ssl_verify
49
+ # @return [Boolean] If the connection should verify SSL on with WinRM (Windows)
50
+ attr_accessor :ssl_verify
51
+
52
+ # @!attribute [rw] tmpdir
53
+ # @return [String] The directory to upload and execute temporary files on the target
54
+ attr_accessor :tmpdir
55
+
56
+ # @!attribute [rw] verbose
57
+ # @return [Boolean] Shows verbose logging
58
+ attr_accessor :verbose
59
+
60
+ # @!attribute [rw] debug
61
+ # @return [Boolean] Shows debug logging
62
+ attr_accessor :debug
63
+
64
+ # @!attribute [rw] facts
65
+ # @return [Hash] A hash of facts for the machine
66
+ attr_accessor :facts
67
+
68
+ # @!attribute [rw] vars
69
+ # @return [Hash] A hash of vars for the machine
70
+ attr_accessor :vars
71
+
72
+ # @!attribute [rw] features
73
+ # @return [Array<String>] An array containing the features for this machine
74
+ attr_accessor :features
75
+
76
+ def initialize
77
+ @bolt_exe = UNSET_VALUE
78
+ @boltdir = UNSET_VALUE
79
+ @host_key_check = UNSET_VALUE
80
+ @modulepath = UNSET_VALUE
81
+ @password = UNSET_VALUE
82
+ @port = UNSET_VALUE
83
+ @private_key = UNSET_VALUE
84
+ @run_as = UNSET_VALUE
85
+ @ssl = UNSET_VALUE
86
+ @ssl_verify = UNSET_VALUE
87
+ @sudo_password = UNSET_VALUE
88
+ @tmpdir = UNSET_VALUE
89
+ @user = UNSET_VALUE
90
+ @verbose = UNSET_VALUE
91
+ @debug = UNSET_VALUE
92
+ @facts = UNSET_VALUE
93
+ @vars = UNSET_VALUE
94
+ @features = UNSET_VALUE
95
+ end
96
+
97
+ def finalize!
98
+ @bolt_exe = 'bolt' if @bolt_exe == UNSET_VALUE
99
+ @boltdir = '.' if @boltdir == UNSET_VALUE
100
+ @host_key_check = nil if @host_key_check == UNSET_VALUE
101
+ @modulepath = 'modules' if @modulepath == UNSET_VALUE
102
+ @port = nil if @port == UNSET_VALUE
103
+ @password = nil if @password == UNSET_VALUE
104
+ @private_key = nil if @private_key == UNSET_VALUE
105
+ @run_as = nil if @run_as == UNSET_VALUE
106
+ @ssl = nil if @ssl == UNSET_VALUE
107
+ @ssl_verify = nil if @ssl_verify == UNSET_VALUE
108
+ @sudo_password = nil if @sudo_password == UNSET_VALUE
109
+ @tmpdir = nil if @tmpdir == UNSET_VALUE
110
+ @user = nil if @user == UNSET_VALUE
111
+ @verbose = nil if @verbose == UNSET_VALUE
112
+ @debug = nil if @debug == UNSET_VALUE
113
+ @facts = nil if @facts == UNSET_VALUE
114
+ @features = nil if @features == UNSET_VALUE
115
+ @vars = nil if @vars == UNSET_VALUE
116
+ end
117
+
118
+ def validate(_machine)
119
+ errors = _detected_errors
120
+
121
+ { "GlobalBolt" => errors }
122
+ end
123
+
124
+ # Generate a bolt inventory config hash for this config
125
+ # @return [Hash] A bolt inventory config hash containing the configured params
126
+ def inventory_config
127
+ group_objects = ['facts', 'features', 'vars']
128
+ config = {}
129
+ instance_variables_hash.each do |key, value|
130
+ next if value.nil?
131
+
132
+ if group_objects.include?(key)
133
+ config[key] = value
134
+ else
135
+ setting_map.each do |transport, settings|
136
+ next unless settings.include?(key)
137
+
138
+ config['config'] ||= {}
139
+ config['config'][transport.to_s] ||= {}
140
+ config['config'][transport.to_s][key.tr('_', '-')] = value
141
+ end
142
+ end
143
+ end
144
+ config
145
+ end
146
+
147
+ # Return the setting map for the config hash
148
+ # @return [Hash] A map of the settings to the transport
149
+ def setting_map
150
+ {
151
+ 'ssh': [
152
+ 'user',
153
+ 'password',
154
+ 'run_as',
155
+ 'port',
156
+ 'private_key',
157
+ 'host_key_check',
158
+ 'sudo_password',
159
+ 'tmpdir',
160
+ ],
161
+ 'winrm': [
162
+ 'user',
163
+ 'password',
164
+ 'run_as',
165
+ 'ssl',
166
+ 'ssl_verify',
167
+ 'port',
168
+ 'tmpdir',
169
+ ],
170
+ }
171
+ end
172
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'config_builder/model'
4
+
5
+ module VagrantBolt::ConfigBuilder
6
+ # Enable config builder loading of this plugin
7
+
8
+ require_relative 'config_builder/provisioner'
9
+ require_relative 'config_builder/config'
10
+ require_relative 'config_builder/triggers'
11
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'config_builder/model'
4
+ require_relative 'monkey_patches'
5
+
6
+ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
7
+ # @!attribute [rw] args
8
+ # @return [String] Additional arguments for the bolt command
9
+ def_model_attribute :args
10
+
11
+ # @!attribute [rw] bolt_exe
12
+ # @return [String] The full path to the bolt command. If not passed in, the default from PATH will be used.
13
+ def_model_attribute :bolt_exe
14
+
15
+ # @!attribute [rw] boltdir
16
+ # @return [String] The bolt working directory. Defaults to `.`
17
+ def_model_attribute :boltdir
18
+
19
+ # @!attribute [rw] debug
20
+ # @return [Boolean] Shows debug logging
21
+ def_model_attribute :debug
22
+
23
+ # @!attribute [rw] host_key_check
24
+ # @return [Boolean] If the connection should check the host key on the remote host (linux)
25
+ def_model_attribute :host_key_check
26
+
27
+ # @!attribute [rw] modulepath
28
+ # @return [String] The path to the modules. Defaults to `modules`.
29
+ def_model_attribute :modulepath
30
+
31
+ # @!attribute [rw] name
32
+ # @return [String] The name of task or plan to run
33
+ def_model_attribute :name
34
+
35
+ # @!attribute [rw] nodes
36
+ # Note: The `node_list` will override this setting.
37
+ # @return [Array<String, Symbol>, "ALL"] The nodes to run the task or plan on.
38
+ # Valid values are an array of machine names or the string "ALL".
39
+ def_model_attribute :nodes
40
+
41
+ # @!attribute [rw] excludes
42
+ # Note: The `node_list` will override this setting.
43
+ # Note: This will be merged with `nodes`, with `excludes` taking precidence.
44
+ # @return [Array<String, Symbol>] The nodes to exclude from running this task or plan on.
45
+ # Valid values are an array of machine names.
46
+ def_model_attribute :excludes
47
+
48
+ # @!attribute [rw] node_list
49
+ # This setting overrides `nodes` and needs to be in the `protocol://ipaddress:port` URI format
50
+ # @return [String] The bolt node list. This defaults to the currnet node.
51
+ def_model_attribute :node_list
52
+
53
+ # @!attribute [rw] noop
54
+ # @return [Boolean] If the command should be run with noop. Only valid with tasks and apply.
55
+ def_model_attribute :noop
56
+
57
+ # @!attribute [rw] params
58
+ # @return [Hash] The paramater hash for the task or plan
59
+ def_model_attribute :params
60
+
61
+ # @!attribute [rw] command
62
+ # @return [Symbol] Whether bolt should use a task or plan
63
+ def_model_attribute :command
64
+
65
+ # @!attribute [rw] user
66
+ # @return [String] The user to authenticate on the machine.
67
+ def_model_attribute :user
68
+
69
+ # @!attribute [rw] password
70
+ # @return [String] The password to authenticate on the machine.
71
+ def_model_attribute :password
72
+
73
+ # @!attribute [rw] port
74
+ # @return [String] The port to connect to the machine.
75
+ def_model_attribute :port
76
+
77
+ # @!attribute [rw] private_key
78
+ # @return [String] The path of the private_key to authenticate on the machine.
79
+ def_model_attribute :private_key
80
+
81
+ # @!attribute [rw] run_as
82
+ # @return [String] User to run as using privilege escalation.
83
+ def_model_attribute :run_as
84
+
85
+ # @!attribute [rw] sudo_password
86
+ # @return [String] The password to authenticate sudo on the machine.
87
+ def_model_attribute :sudo_password
88
+
89
+ # @!attribute [rw] ssl
90
+ # @return [Boolean] If the connection should use SSL on with WinRM (Windows)
91
+ def_model_attribute :ssl
92
+
93
+ # @!attribute [rw] ssl_verify
94
+ # @return [Boolean] If the connection should verify SSL on with WinRM (Windows)
95
+ def_model_attribute :ssl_verify
96
+
97
+ # @!attribute [rw] tmpdir
98
+ # @return [String] The directory to upload and execute temporary files on the target
99
+ def_model_attribute :tmpdir
100
+
101
+ # @!attribute [rw] verbose
102
+ # @return [Boolean] Shows verbose logging
103
+ def_model_attribute :verbose
104
+
105
+ # @!attribute [rw] facts
106
+ # @return [Hash] A hash of facts for the machine
107
+ def_model_attribute :facts
108
+
109
+ # @!attribute [rw] vars
110
+ # @return [Hash] A hash of vars for the machine
111
+ def_model_attribute :vars
112
+
113
+ # @!attribute [rw] features
114
+ # @return [Array<String>] An array containing the features for this machine
115
+ def_model_attribute :features
116
+
117
+ # rubocop:disable Metrics/BlockLength
118
+ def to_proc
119
+ proc do |config|
120
+ bolt = config.bolt
121
+ with_attr(:args) { |val| bolt.args = val }
122
+ with_attr(:bolt_exe) { |val| bolt.bolt_exe = val }
123
+ with_attr(:command) { |val| bolt.command = val }
124
+ with_attr(:boltdir) { |val| bolt.boltdir = val }
125
+ with_attr(:debug) { |val| bolt.debug = val }
126
+ with_attr(:host_key_check) { |val| bolt.host_key_check = val }
127
+ with_attr(:modulepath) { |val| bolt.modulepath = val }
128
+ with_attr(:name) { |val| bolt.name = val }
129
+ with_attr(:nodes) { |val| bolt.nodes = val }
130
+ with_attr(:noop) { |val| bolt.noop = val }
131
+ with_attr(:excludes) { |val| bolt.excludes = val }
132
+ with_attr(:node_list) { |val| bolt.node_list = val }
133
+ with_attr(:params) { |val| bolt.params = val }
134
+ with_attr(:user) { |val| bolt.user = val }
135
+ with_attr(:password) { |val| bolt.password = val }
136
+ with_attr(:port) { |val| bolt.port = val }
137
+ with_attr(:private_key) { |val| bolt.private_key = val }
138
+ with_attr(:run_as) { |val| bolt.run_as = val }
139
+ with_attr(:sudo_password) { |val| bolt.sudo_password = val }
140
+ with_attr(:ssl) { |val| bolt.ssl = val }
141
+ with_attr(:ssl_verify) { |val| bolt.ssl_verify = val }
142
+ with_attr(:tmpdir) { |val| bolt.tmpdir = val }
143
+ with_attr(:verbose) { |val| bolt.verbose = val }
144
+ with_attr(:facts) { |val| bolt.facts = val }
145
+ with_attr(:features) { |val| bolt.features = val }
146
+ with_attr(:vars) { |val| bolt.vars = val }
147
+ end
148
+ end
149
+ # rubocop:enable Metrics/BlockLength
150
+ end