vagrant-bolt 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +0 -8
- data/.travis.yml +1 -1
- data/CHANGELOG.md +16 -2
- data/Gemfile +2 -2
- data/README.md +21 -14
- data/acceptance/components/bolt_spec.rb +11 -11
- data/acceptance/skeletons/advanced/Vagrantfile +1 -1
- data/acceptance/skeletons/base/Vagrantfile +1 -0
- data/lib/vagrant-bolt/config/bolt.rb +28 -8
- data/lib/vagrant-bolt/config_builder/config.rb +19 -4
- data/lib/vagrant-bolt/config_builder/monkey_patches.rb +2 -2
- data/lib/vagrant-bolt/config_builder/provisioner.rb +15 -3
- data/lib/vagrant-bolt/runner.rb +8 -8
- data/lib/vagrant-bolt/util/bolt.rb +5 -5
- data/lib/vagrant-bolt/util/machine.rb +1 -1
- data/lib/vagrant-bolt/version.rb +1 -1
- data/spec/unit/config/bolt_spec.rb +2 -0
- data/spec/unit/runner/runner_spec.rb +27 -11
- data/spec/unit/util/bolt_spec.rb +5 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 534ab9c0b5855064fd04ab2ff43924dd4fcf64360d9505deb9fa1c87fa80dd87
|
4
|
+
data.tar.gz: f0a2dbbaf6dc37a1dcb3bd014eacc01b7b3b2ea0e3fab04089546490b206463e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de73c711587dbff8917abfed452aef34ba2fabca22f67d79b291ec9a5548ac279617065e9d8e7cadde3ee05b57d3d79e5781b53d0f06bd1e97ec8b8ff671590d
|
7
|
+
data.tar.gz: 8afd8928752874c3d93bf64cc7de893542138a8ee5a7d0b4ac4617410a0f505cb70d8f7ad7aed9df2fc6a473aebab5817e21efb7bade5cfdcbcf19cba4e80f38
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -96,14 +96,6 @@ Metrics/CyclomaticComplexity:
|
|
96
96
|
Enabled: false
|
97
97
|
Metrics/PerceivedComplexity:
|
98
98
|
Enabled: false
|
99
|
-
Metrics/MethodLength:
|
100
|
-
Enabled: true
|
101
|
-
ExcludedMethods:
|
102
|
-
- initialize
|
103
|
-
- finalize!
|
104
|
-
- validate
|
105
|
-
- to_proc
|
106
|
-
Max: 25
|
107
99
|
Metrics/ClassLength:
|
108
100
|
Enabled: false
|
109
101
|
Metrics/ModuleLength:
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [v0.2.0](https://github.com/oscar-stack/vagrant-bolt/tree/v0.2.0) (2020-02-26)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/oscar-stack/vagrant-bolt/compare/v0.1.2...v0.2.0)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Change nodes to targets in config [\#14](https://github.com/oscar-stack/vagrant-bolt/pull/14) ([jarretlavallee](https://github.com/jarretlavallee))
|
10
|
+
- Update to Bolt inventory v2 [\#12](https://github.com/oscar-stack/vagrant-bolt/pull/12) ([jarretlavallee](https://github.com/jarretlavallee))
|
2
11
|
|
3
12
|
## [v0.1.2](https://github.com/oscar-stack/vagrant-bolt/tree/v0.1.2) (2019-10-17)
|
13
|
+
|
4
14
|
[Full Changelog](https://github.com/oscar-stack/vagrant-bolt/compare/v0.1.1...v0.1.2)
|
5
15
|
|
6
16
|
**Merged pull requests:**
|
@@ -9,6 +19,7 @@
|
|
9
19
|
- Fix changelog version tag [\#10](https://github.com/oscar-stack/vagrant-bolt/pull/10) ([jarretlavallee](https://github.com/jarretlavallee))
|
10
20
|
|
11
21
|
## [v0.1.1](https://github.com/oscar-stack/vagrant-bolt/tree/v0.1.1) (2019-07-01)
|
22
|
+
|
12
23
|
[Full Changelog](https://github.com/oscar-stack/vagrant-bolt/compare/v0.1.0...v0.1.1)
|
13
24
|
|
14
25
|
**Merged pull requests:**
|
@@ -18,6 +29,9 @@
|
|
18
29
|
- Add connect\_timeout option to inventory [\#7](https://github.com/oscar-stack/vagrant-bolt/pull/7) ([jarretlavallee](https://github.com/jarretlavallee))
|
19
30
|
|
20
31
|
## [v0.1.0](https://github.com/oscar-stack/vagrant-bolt/tree/v0.1.0) (2018-12-11)
|
32
|
+
|
33
|
+
[Full Changelog](https://github.com/oscar-stack/vagrant-bolt/compare/4574482459a0f320bb6b25557199a1612b19ea72...v0.1.0)
|
34
|
+
|
21
35
|
**Merged pull requests:**
|
22
36
|
|
23
37
|
- \(SUP-874\) Add a command line interface [\#6](https://github.com/oscar-stack/vagrant-bolt/pull/6) ([jarretlavallee](https://github.com/jarretlavallee))
|
@@ -29,4 +43,4 @@
|
|
29
43
|
|
30
44
|
|
31
45
|
|
32
|
-
\* *This
|
46
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
source 'https://rubygems.org'
|
4
4
|
require 'rubygems/version'
|
5
5
|
|
6
|
-
vagrant_branch = ENV['TEST_VAGRANT_VERSION'] || 'v2.2.
|
6
|
+
vagrant_branch = ENV['TEST_VAGRANT_VERSION'] || 'v2.2.7'
|
7
7
|
|
8
8
|
group :plugins do
|
9
9
|
gemspec
|
@@ -31,7 +31,7 @@ group :test do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
group :system_tests do
|
34
|
-
gem 'bolt', "
|
34
|
+
gem 'bolt', "~> 1.48.0"
|
35
35
|
end
|
36
36
|
|
37
37
|
|
data/README.md
CHANGED
@@ -177,13 +177,13 @@ VagrantBolt.task('facts', env, machine, user: 'ubuntu', password: 'testpassword'
|
|
177
177
|
Run the `facts` plan on `server1` and `server2`.
|
178
178
|
|
179
179
|
~~~ruby
|
180
|
-
VagrantBolt.plan('facts', env, machine,
|
180
|
+
VagrantBolt.plan('facts', env, machine, targets: [:server1, :server2])
|
181
181
|
~~~
|
182
182
|
|
183
|
-
Run the `hostname` command on all
|
183
|
+
Run the `hostname` command on all targets.
|
184
184
|
|
185
185
|
~~~ruby
|
186
|
-
VagrantBolt.command('/bin/hostname', env, machine,
|
186
|
+
VagrantBolt.command('/bin/hostname', env, machine, targets: 'all')
|
187
187
|
~~~
|
188
188
|
|
189
189
|
Run the `service::linux` task as `root` to restart `cron` with a specific path to the bolt executable. This configuration specifies params for the `service::linux` task.
|
@@ -220,20 +220,20 @@ The settings available in the triggers and the provisioner are the same.
|
|
220
220
|
* `boltdir`
|
221
221
|
* Description: A string containing the bolt working directory
|
222
222
|
* Default: The vagrant root
|
223
|
-
* `
|
224
|
-
* Description: A string containing bolt
|
225
|
-
* This will override `
|
226
|
-
* Default: `%{protocol}://%{ssh_ip}:%{ssh_port}` if `
|
227
|
-
* `
|
223
|
+
* `target_list`
|
224
|
+
* Description: A string containing bolt target list in URI format
|
225
|
+
* This will override `targets` and `excludes`
|
226
|
+
* Default: `%{protocol}://%{ssh_ip}:%{ssh_port}` if `targets` is not specified
|
227
|
+
* `targets`
|
228
228
|
* Description: An array of machine names to run the task or plan on
|
229
|
-
* The `
|
229
|
+
* The `target_list` will override this setting.
|
230
230
|
* A special `ALL` string can be used instead of an array to use all active machines in the environment
|
231
231
|
* Valid Values: An array of machine symbols or the string "ALL"
|
232
232
|
* Default: `[]`
|
233
233
|
* `excludes`
|
234
234
|
* Description: An array of machine names to not run the task on
|
235
|
-
* The `
|
236
|
-
* This setting will take precidence over `
|
235
|
+
* The `target_list` will override this setting.
|
236
|
+
* This setting will take precidence over `targets`
|
237
237
|
* Valid Values: An array of machine symbols
|
238
238
|
* Default: `[]`
|
239
239
|
* `params`
|
@@ -277,7 +277,14 @@ The settings available in the triggers and the provisioner are the same.
|
|
277
277
|
* `vars`
|
278
278
|
* Description: A hash containing arbitrary data that may be passed to run_* functions or used for logic in plans
|
279
279
|
* `facts`
|
280
|
-
* Description: A hash containing observed information about the
|
280
|
+
* Description: A hash containing observed information about the target including what can be collected by Facter
|
281
|
+
|
282
|
+
**Deprecated Parameters**
|
283
|
+
|
284
|
+
* `node_list`
|
285
|
+
* Replaced by `target_list`
|
286
|
+
* `nodes`
|
287
|
+
* Replaced by `targets`
|
281
288
|
|
282
289
|
Config Builder
|
283
290
|
--------------
|
@@ -373,7 +380,7 @@ The command can be used to deploy the Puppetfile, for example.
|
|
373
380
|
vagrant bolt puppetfile install
|
374
381
|
~~~
|
375
382
|
|
376
|
-
It can be used to run ad-hoc tasks on a
|
383
|
+
It can be used to run ad-hoc tasks on a target by specifying the target by its machine name.
|
377
384
|
|
378
385
|
~~~shell
|
379
386
|
vagrant bolt -u task run facts -n server
|
@@ -390,7 +397,7 @@ vagrant bolt command run 'date' -n agent,master
|
|
390
397
|
Other Use Cases
|
391
398
|
---------------
|
392
399
|
|
393
|
-
There are some other use cases for Vagrant Bolt. One of which is to not use the triggers or provisioning to run bolt commands on the
|
400
|
+
There are some other use cases for Vagrant Bolt. One of which is to not use the triggers or provisioning to run bolt commands on the targets, but to manage the inventory file for manual testing. This can easily be accomplished by using a trigger to manage the `inventory.yaml` file and specifying the configuration for the targets in the config based on the options above. Below is an example trigger that will manage a `./inventory.yaml` file for use with external bolt commands.
|
394
401
|
|
395
402
|
~~~ruby
|
396
403
|
require 'vagrant-bolt'
|
@@ -24,7 +24,7 @@ shared_examples 'provider/virtualbox' do |provider, options|
|
|
24
24
|
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt task run 'facts'})
|
25
25
|
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt plan run 'facts'})
|
26
26
|
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run})
|
27
|
-
expect(@result.stdout.scan(%r{Successful on 1
|
27
|
+
expect(@result.stdout.scan(%r{Successful on 1 target}).size).to eq(3)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -39,7 +39,7 @@ shared_examples 'provider/virtualbox' do |provider, options|
|
|
39
39
|
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt task run 'facts'})
|
40
40
|
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt plan run 'facts'})
|
41
41
|
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run})
|
42
|
-
expect(@result.stdout.scan(%r{Successful on 1
|
42
|
+
expect(@result.stdout.scan(%r{Successful on 1 target}).size).to eq(3)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -50,18 +50,18 @@ shared_examples 'provider/virtualbox' do |provider, options|
|
|
50
50
|
|
51
51
|
it 'runs a task, plan, and command' do
|
52
52
|
expect(@result.exit_code).to eq(0)
|
53
|
-
result = assert_execute('vagrant', 'bolt', 'task', 'run', 'facts', '-
|
53
|
+
result = assert_execute('vagrant', 'bolt', 'task', 'run', 'facts', '-t', 'server')
|
54
54
|
expect(result.exit_code).to eq(0)
|
55
55
|
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: '\/[^\ ]+bolt' 'task' 'run' 'facts'})
|
56
|
-
expect(result.stdout.scan(%r{Successful on 1
|
57
|
-
result = assert_execute('vagrant', 'bolt', 'plan', 'run', 'facts', '-
|
56
|
+
expect(result.stdout.scan(%r{Successful on 1 target}).size).to eq(1)
|
57
|
+
result = assert_execute('vagrant', 'bolt', 'plan', 'run', 'facts', '-t', 'server')
|
58
58
|
expect(result.exit_code).to eq(0)
|
59
59
|
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: '\/[^\ ]+bolt' 'plan' 'run' 'facts'})
|
60
|
-
expect(result.stdout.scan(%r{Successful on 1
|
61
|
-
result = assert_execute('vagrant', 'bolt', 'command', 'run', 'hostname', '-
|
60
|
+
expect(result.stdout.scan(%r{Successful on 1 target}).size).to eq(1)
|
61
|
+
result = assert_execute('vagrant', 'bolt', 'command', 'run', 'hostname', '-t', 'server')
|
62
62
|
expect(result.exit_code).to eq(0)
|
63
63
|
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: '\/[^\ ]+bolt' 'command' 'run'})
|
64
|
-
expect(result.stdout.scan(%r{Successful on 1
|
64
|
+
expect(result.stdout.scan(%r{Successful on 1 target}).size).to eq(1)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -79,14 +79,14 @@ shared_examples 'provider/virtualbox' do |provider, options|
|
|
79
79
|
# Check for root level triggers
|
80
80
|
result = assert_execute('vagrant', 'provision')
|
81
81
|
expect(result.exit_code).to eq(0)
|
82
|
-
# Ensure that the trigger is run on both
|
82
|
+
# Ensure that the trigger is run on both targets
|
83
83
|
expect(result.stdout.scan(%r{server[12]:\s+allnodetest}).size).to eq(4)
|
84
|
-
# Ensure that '
|
84
|
+
# Ensure that 'targets = all' includes both targets
|
85
85
|
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run[^\n]+allnodetest[^\n]+server[12],server[12]})
|
86
86
|
# Ensure that the root level `run_as` is used
|
87
87
|
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run[^\n]+allnodetest[^\n]+--run-as 'root'})
|
88
88
|
## Configtest
|
89
|
-
# Ensure excludes overrides
|
89
|
+
# Ensure excludes overrides targets
|
90
90
|
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run[^\n]+configtest[^\n]+server2})
|
91
91
|
# Ensure verbose and debug flags are correctly handled
|
92
92
|
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run[^\n]+configtest[^\n]+--verbose})
|
@@ -6,7 +6,7 @@ Vagrant.configure('2') do |config|
|
|
6
6
|
# Run a trigger on all nodes after provision
|
7
7
|
config.trigger.after :provision do |trigger|
|
8
8
|
trigger.ruby do |env, machine|
|
9
|
-
VagrantBolt.command('/bin/echo "allnodetest"', env, machine,
|
9
|
+
VagrantBolt.command('/bin/echo "allnodetest"', env, machine, targets: 'all')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
config.vm.define 'server1' do |node|
|
@@ -10,6 +10,7 @@ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
|
|
10
10
|
attr_accessor :name
|
11
11
|
|
12
12
|
# @!attribute [rw] nodes
|
13
|
+
# DEPRECATED. Use `targets` instead.
|
13
14
|
# Note: The `node_list` will override this setting.
|
14
15
|
# @return [Array<String, Symbol>, "ALL"] The nodes to run the task or plan on.
|
15
16
|
# Valid values are an array of machine names or the string "ALL".
|
@@ -17,14 +18,15 @@ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
|
|
17
18
|
|
18
19
|
# @!attribute [rw] excludes
|
19
20
|
# Note: The `node_list` will override this setting.
|
20
|
-
# Note: This will be merged with `
|
21
|
-
# @return [Array<String, Symbol>] The
|
21
|
+
# Note: This will be merged with `targets`, with `excludes` taking precidence.
|
22
|
+
# @return [Array<String, Symbol>] The targets to exclude from running this task or plan on.
|
22
23
|
# Valid values are an array of machine names.
|
23
24
|
attr_accessor :excludes
|
24
25
|
|
25
26
|
# @!attribute [rw] node_list
|
27
|
+
# DEPRECATED. Use `target_list` instead.
|
26
28
|
# 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
|
29
|
+
# @return [String] The bolt node list. This defaults to the currnet machine.
|
28
30
|
attr_accessor :node_list
|
29
31
|
|
30
32
|
# @!attribute [rw] params
|
@@ -39,6 +41,17 @@ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
|
|
39
41
|
# @return [Boolean] If the command should be run with noop. Only valid with tasks and apply.
|
40
42
|
attr_accessor :noop
|
41
43
|
|
44
|
+
# @!attribute [rw] targets
|
45
|
+
# Note: The `target_list` will override this setting.
|
46
|
+
# @return [Array<String, Symbol>, "ALL"] The targets to run the task or plan on.
|
47
|
+
# Valid values are an array of machine names or the string "ALL".
|
48
|
+
attr_accessor :targets
|
49
|
+
|
50
|
+
# @!attribute [rw] target_list
|
51
|
+
# This setting overrides `targets` and needs to be in the `protocol://ipaddress:port` URI format.
|
52
|
+
# @return [String] The bolt target list. This defaults to the currnet machine.
|
53
|
+
attr_accessor :target_list
|
54
|
+
|
42
55
|
def initialize
|
43
56
|
super
|
44
57
|
@args = UNSET_VALUE
|
@@ -48,6 +61,8 @@ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
|
|
48
61
|
@node_list = UNSET_VALUE
|
49
62
|
@params = UNSET_VALUE
|
50
63
|
@command = UNSET_VALUE
|
64
|
+
@targets = []
|
65
|
+
@target_list = UNSET_VALUE
|
51
66
|
end
|
52
67
|
|
53
68
|
def finalize!
|
@@ -73,15 +88,18 @@ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
|
|
73
88
|
@params = nil if @params == UNSET_VALUE
|
74
89
|
@command = nil if @command == UNSET_VALUE
|
75
90
|
@noop = nil if @noop == UNSET_VALUE
|
91
|
+
# Use nodes if targets is not specified.
|
92
|
+
@targets = @nodes if @targets.empty?
|
93
|
+
@target_list = @node_list if (@target_list == UNSET_VALUE) || @target_list.nil?
|
76
94
|
end
|
77
95
|
|
78
96
|
def merge(other)
|
79
97
|
super.tap do |result|
|
80
98
|
new_excludes = (excludes + other.excludes.dup).flatten.uniq
|
81
99
|
result.instance_variable_set(:@excludes, new_excludes.to_a)
|
82
|
-
unless
|
83
|
-
|
84
|
-
result.instance_variable_set(:@
|
100
|
+
unless targets.to_s.casecmp("all").zero?
|
101
|
+
new_targets = (targets + other.targets.dup).flatten.uniq
|
102
|
+
result.instance_variable_set(:@targets, new_targets.to_a)
|
85
103
|
end
|
86
104
|
end
|
87
105
|
end
|
@@ -90,9 +108,9 @@ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
|
|
90
108
|
errors = _detected_errors
|
91
109
|
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
110
|
|
93
|
-
if @
|
111
|
+
if @targets.nil? || (!(@targets.is_a? Array) && !@targets.to_s.casecmp("all").zero?)
|
94
112
|
errors << I18n.t('vagrant-bolt.config.bolt.errors.invalid_data_command',
|
95
|
-
item: '
|
113
|
+
item: 'targets',
|
96
114
|
command: 'array')
|
97
115
|
end
|
98
116
|
|
@@ -121,8 +139,10 @@ class VagrantBolt::Config::Bolt < VagrantBolt::Config::Global
|
|
121
139
|
def blacklist
|
122
140
|
[
|
123
141
|
'nodes',
|
142
|
+
'targets',
|
124
143
|
'excludes',
|
125
144
|
'node_list',
|
145
|
+
'target_list',
|
126
146
|
'bolt_exe',
|
127
147
|
'args',
|
128
148
|
'command',
|
@@ -37,21 +37,23 @@ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
|
|
37
37
|
def_model_attribute :name
|
38
38
|
|
39
39
|
# @!attribute [rw] nodes
|
40
|
+
# DEPRECATED. Use `targets` instead.
|
40
41
|
# Note: The `node_list` will override this setting.
|
41
42
|
# @return [Array<String, Symbol>, "ALL"] The nodes to run the task or plan on.
|
42
43
|
# Valid values are an array of machine names or the string "ALL".
|
43
44
|
def_model_attribute :nodes
|
44
45
|
|
45
46
|
# @!attribute [rw] excludes
|
46
|
-
# Note: The `
|
47
|
-
# Note: This will be merged with `
|
48
|
-
# @return [Array<String, Symbol>] The
|
47
|
+
# Note: The `target_list` will override this setting.
|
48
|
+
# Note: This will be merged with `targets`, with `excludes` taking precidence.
|
49
|
+
# @return [Array<String, Symbol>] The targets to exclude from running this task or plan on.
|
49
50
|
# Valid values are an array of machine names.
|
50
51
|
def_model_attribute :excludes
|
51
52
|
|
52
53
|
# @!attribute [rw] node_list
|
54
|
+
# DEPRECATED. Use `target_list` instead.
|
53
55
|
# This setting overrides `nodes` and needs to be in the `protocol://ipaddress:port` URI format
|
54
|
-
# @return [String] The bolt node list. This defaults to the
|
56
|
+
# @return [String] The bolt node list. This defaults to the current node.
|
55
57
|
def_model_attribute :node_list
|
56
58
|
|
57
59
|
# @!attribute [rw] noop
|
@@ -98,6 +100,17 @@ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
|
|
98
100
|
# @return [Boolean] If the connection should verify SSL on with WinRM (Windows)
|
99
101
|
def_model_attribute :ssl_verify
|
100
102
|
|
103
|
+
# @!attribute [rw] targets
|
104
|
+
# Note: The `target_list` will override this setting.
|
105
|
+
# @return [Array<String, Symbol>, "ALL"] The targets to run the task or plan on.
|
106
|
+
# Valid values are an array of machine names or the string "ALL".
|
107
|
+
def_model_attribute :targets
|
108
|
+
|
109
|
+
# @!attribute [rw] target_list
|
110
|
+
# This setting overrides `targets` and needs to be in the `protocol://ipaddress:port` URI format
|
111
|
+
# @return [String] The bolt target list. This defaults to the current target.
|
112
|
+
def_model_attribute :target_list
|
113
|
+
|
101
114
|
# @!attribute [rw] tmpdir
|
102
115
|
# @return [String] The directory to upload and execute temporary files on the target
|
103
116
|
def_model_attribute :tmpdir
|
@@ -144,6 +157,8 @@ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
|
|
144
157
|
with_attr(:sudo_password) { |val| bolt.sudo_password = val }
|
145
158
|
with_attr(:ssl) { |val| bolt.ssl = val }
|
146
159
|
with_attr(:ssl_verify) { |val| bolt.ssl_verify = val }
|
160
|
+
with_attr(:targets) { |val| bolt.targets = val }
|
161
|
+
with_attr(:target_list) { |val| bolt.target_list = val }
|
147
162
|
with_attr(:tmpdir) { |val| bolt.tmpdir = val }
|
148
163
|
with_attr(:verbose) { |val| bolt.verbose = val }
|
149
164
|
with_attr(:facts) { |val| bolt.facts = val }
|
@@ -29,7 +29,7 @@ module VagrantBolt::ConfigBuilder::MonkeyPatches
|
|
29
29
|
|
30
30
|
def eval_bolt_triggers_root(vm_root_config)
|
31
31
|
# Configure the vm bolt object if the options exist
|
32
|
-
triggers = attr(:bolt_triggers) || []
|
32
|
+
triggers = attr(:bolt_triggers) || []
|
33
33
|
triggers.each do |config|
|
34
34
|
f = VagrantBolt::ConfigBuilder::Triggers.new_from_hash(config)
|
35
35
|
f.call(vm_root_config)
|
@@ -47,7 +47,7 @@ ConfigBuilder::Model::VM.prepend(VagrantBolt::ConfigBuilder::MonkeyPatches)
|
|
47
47
|
# Allow for the role filter to handle bolt configs and bolt_triggers
|
48
48
|
# @!visibility private
|
49
49
|
module VagrantBolt::ConfigBuilder::MonkeyPatches::FilterRoles
|
50
|
-
def
|
50
|
+
def merge_targets!(left, right)
|
51
51
|
super.tap do |result|
|
52
52
|
array_keys = ['bolt_triggers']
|
53
53
|
array_keys.each do |key|
|
@@ -37,6 +37,7 @@ class VagrantBolt::ConfigBuilder::Provisioner < ConfigBuilder::Model::Provisione
|
|
37
37
|
def_model_attribute :name
|
38
38
|
|
39
39
|
# @!attribute [rw] nodes
|
40
|
+
# DEPRECATED. Use `targets` instead.
|
40
41
|
# Note: The `node_list` will override this setting.
|
41
42
|
# @return [Array<String, Symbol>, "ALL"] The nodes to run the task or plan on.
|
42
43
|
# Valid values are an array of machine names or the string "ALL".
|
@@ -47,9 +48,9 @@ class VagrantBolt::ConfigBuilder::Provisioner < ConfigBuilder::Model::Provisione
|
|
47
48
|
def_model_attribute :noop
|
48
49
|
|
49
50
|
# @!attribute [rw] excludes
|
50
|
-
# Note: The `
|
51
|
-
# Note: This will be merged with `
|
52
|
-
# @return [Array<String, Symbol>] The
|
51
|
+
# Note: The `target_list` will override this setting.
|
52
|
+
# Note: This will be merged with `targets`, with `excludes` taking precidence.
|
53
|
+
# @return [Array<String, Symbol>] The targets to exclude from running this task or plan on.
|
53
54
|
# Valid values are an array of machine names.
|
54
55
|
def_model_attribute :excludes
|
55
56
|
|
@@ -98,6 +99,17 @@ class VagrantBolt::ConfigBuilder::Provisioner < ConfigBuilder::Model::Provisione
|
|
98
99
|
# @return [Boolean] If the connection should verify SSL on with WinRM (Windows)
|
99
100
|
def_model_attribute :ssl_verify
|
100
101
|
|
102
|
+
# @!attribute [rw] targets
|
103
|
+
# Note: The `target_list` will override this setting.
|
104
|
+
# @return [Array<String, Symbol>, "ALL"] The targets to run the task or plan on.
|
105
|
+
# Valid values are an array of machine names or the string "ALL".
|
106
|
+
def_model_attribute :targets
|
107
|
+
|
108
|
+
# @!attribute [rw] target_list
|
109
|
+
# This setting overrides `targets` and needs to be in the `protocol://ipaddress:port` URI format
|
110
|
+
# @return [String] The bolt target list. This defaults to the current target.
|
111
|
+
def_model_attribute :target_list
|
112
|
+
|
101
113
|
# @!attribute [rw] tmpdir
|
102
114
|
# @return [String] The directory to upload and execute temporary files on the target
|
103
115
|
def_model_attribute :tmpdir
|
data/lib/vagrant-bolt/runner.rb
CHANGED
@@ -16,12 +16,12 @@ class VagrantBolt::Runner
|
|
16
16
|
# @param [Symbol, String] command The command of bolt to run; task or plan
|
17
17
|
# @param [String] name The name of the bolt task or plan to run
|
18
18
|
# @param [Hash] args A optional hash of bolt config overrides. No merging will be done with the overrides
|
19
|
-
# @example run('task', 'facts', {
|
19
|
+
# @example run('task', 'facts', {targets: ["machinename"]})
|
20
20
|
def run(command, name, **args)
|
21
21
|
@boltconfig = setup_overrides(command, name, **args)
|
22
|
-
# Don't run anything if there are
|
23
|
-
# TODO: Gate this in a more efficient manner. It is possible to run plans without a
|
24
|
-
return if @boltconfig.
|
22
|
+
# Don't run anything if there are targets to run it on
|
23
|
+
# TODO: Gate this in a more efficient manner. It is possible to run plans without a target list.
|
24
|
+
return if @boltconfig.target_list.nil?
|
25
25
|
|
26
26
|
@inventory_path = VagrantBolt::Util::Bolt.update_inventory_file(@env)
|
27
27
|
validate
|
@@ -44,10 +44,10 @@ class VagrantBolt::Runner
|
|
44
44
|
config = VagrantBolt::Util::Config.merge_config(config, @env.vagrantfile.config.bolt)
|
45
45
|
# Add any additional arguments to the config object
|
46
46
|
config.set_options(args) unless args.nil?
|
47
|
-
# Configure the
|
48
|
-
config.
|
49
|
-
config.
|
50
|
-
config.
|
47
|
+
# Configure the target_list based on the config
|
48
|
+
config.target_list ||= [config.targets - config.excludes].flatten.join(',') unless config.targets.empty? || config.targets.to_s.casecmp("all").zero?
|
49
|
+
config.target_list ||= [VagrantBolt::Util::Machine.machines_in_environment(@env).map(&:name) - config.excludes].flatten.join(',') if config.targets.to_s.casecmp("all").zero?
|
50
|
+
config.target_list ||= @machine.name.to_s unless config.excludes.include?(@machine.name.to_s)
|
51
51
|
|
52
52
|
# Ensure these are absolute paths to allow for running vagrant commands outside of the root dir
|
53
53
|
config.modulepath = VagrantBolt::Util::Config.relative_path(config.modulepath, @env.root_path)
|
@@ -36,7 +36,7 @@ module VagrantBolt::Util
|
|
36
36
|
end
|
37
37
|
|
38
38
|
command << "--inventoryfile \'#{inventory_path}\'" unless inventory_path.nil?
|
39
|
-
command << "--
|
39
|
+
command << "--targets \'#{config.target_list}\'" unless config.target_list.nil?
|
40
40
|
command << config.args unless config.args.nil?
|
41
41
|
command.flatten.join(" ")
|
42
42
|
end
|
@@ -45,12 +45,12 @@ module VagrantBolt::Util
|
|
45
45
|
# @param env [Object] The env object
|
46
46
|
# @return [Hash] The hash of config options for the inventory.yaml
|
47
47
|
def self.generate_inventory_hash(env)
|
48
|
-
inventory = { '
|
48
|
+
inventory = { 'version' => 2, 'targets' => [] }
|
49
49
|
inventory.merge!(env.vagrantfile.config.bolt.inventory_config.compact)
|
50
|
-
VagrantBolt::Util::Machine.
|
50
|
+
VagrantBolt::Util::Machine.machines_in_environment(env).each do |vm|
|
51
51
|
next unless VagrantBolt::Util::Machine.running?(vm)
|
52
52
|
|
53
|
-
inventory['
|
53
|
+
inventory['targets'] << generate_node_hash(vm)
|
54
54
|
end
|
55
55
|
inventory.compact
|
56
56
|
end
|
@@ -70,7 +70,7 @@ module VagrantBolt::Util
|
|
70
70
|
transport = VagrantBolt::Util::Machine.windows?(machine) ? 'winrm' : 'ssh'
|
71
71
|
node_hash['config'][transport] = machine_transport_hash(machine, machine_config, ssh_info).compact
|
72
72
|
node_hash['config']['transport'] = transport
|
73
|
-
node_hash['
|
73
|
+
node_hash['uri'] = "#{transport}://#{ssh_info[:host]}:#{node_hash['config'][transport]['port']}"
|
74
74
|
machine_config.each do |key, value|
|
75
75
|
next if key == 'config' || value.nil? || value.empty?
|
76
76
|
|
@@ -32,7 +32,7 @@ module VagrantBolt::Util
|
|
32
32
|
# Generate a list of active machines in the environment
|
33
33
|
# @param env [Object] The Environment
|
34
34
|
# @return [Array<Object>]
|
35
|
-
def self.
|
35
|
+
def self.machines_in_environment(env)
|
36
36
|
env.active_machines.map { |vm|
|
37
37
|
begin
|
38
38
|
env.machine(*vm)
|
data/lib/vagrant-bolt/version.rb
CHANGED
@@ -72,6 +72,7 @@ describe VagrantBolt::Config::Bolt do
|
|
72
72
|
context "defaults" do
|
73
73
|
expected_values = {
|
74
74
|
nodes: [],
|
75
|
+
targets: [],
|
75
76
|
excludes: [],
|
76
77
|
}
|
77
78
|
expected_values.each do |val, expected|
|
@@ -86,6 +87,7 @@ describe VagrantBolt::Config::Bolt do
|
|
86
87
|
"command",
|
87
88
|
"params",
|
88
89
|
"node_list",
|
90
|
+
"target_list",
|
89
91
|
"user",
|
90
92
|
"password",
|
91
93
|
"port",
|
@@ -46,7 +46,7 @@ describe VagrantBolt::Runner do
|
|
46
46
|
|
47
47
|
context 'setup_overrides' do
|
48
48
|
before(:each) do
|
49
|
-
allow(VagrantBolt::Util::Machine).to receive(:
|
49
|
+
allow(VagrantBolt::Util::Machine).to receive(:machines_in_environment).with(iso_env).and_return([machine, machine2])
|
50
50
|
end
|
51
51
|
it 'adds the command and name to the config' do
|
52
52
|
result = subject.send(:setup_overrides, 'task', 'foo')
|
@@ -54,31 +54,47 @@ describe VagrantBolt::Runner do
|
|
54
54
|
expect(result.name).to eq('foo')
|
55
55
|
end
|
56
56
|
|
57
|
-
it 'uses the server name for the
|
57
|
+
it 'uses the server name for the targets' do
|
58
58
|
result = subject.send(:setup_overrides, 'task', 'foo')
|
59
|
-
expect(result.
|
59
|
+
expect(result.target_list).to eq('server')
|
60
60
|
end
|
61
61
|
|
62
|
-
it 'allows for using multiple
|
62
|
+
it 'allows for using multiple targets' do
|
63
|
+
config.targets = ['server', 'server2']
|
64
|
+
config.finalize!
|
65
|
+
result = subject.send(:setup_overrides, 'task', 'foo')
|
66
|
+
expect(result.target_list).to eq('server,server2')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'allows for using nodes parameter' do
|
63
70
|
config.nodes = ['server', 'server2']
|
64
71
|
config.finalize!
|
65
72
|
result = subject.send(:setup_overrides, 'task', 'foo')
|
66
|
-
expect(result.
|
73
|
+
expect(result.target_list).to eq('server,server2')
|
67
74
|
end
|
68
75
|
|
69
|
-
it 'adds all
|
70
|
-
config.
|
76
|
+
it 'adds all targets when "all" is specified' do
|
77
|
+
config.targets = 'all'
|
71
78
|
config.finalize!
|
72
79
|
result = subject.send(:setup_overrides, 'task', 'foo')
|
73
|
-
expect(result.
|
80
|
+
expect(result.target_list).to eq('server,server2')
|
74
81
|
end
|
75
82
|
|
76
83
|
it 'does not override specified ssh settings' do
|
84
|
+
config.target_list = 'ssh://test:22'
|
85
|
+
config.user = 'root'
|
86
|
+
config.finalize!
|
87
|
+
result = subject.send(:setup_overrides, 'task', 'foo')
|
88
|
+
expect(result.target_list).to eq('ssh://test:22')
|
89
|
+
expect(result.user).to eq('root')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'target_list defaults to node_list' do
|
77
93
|
config.node_list = 'ssh://test:22'
|
78
94
|
config.user = 'root'
|
79
95
|
config.finalize!
|
80
96
|
result = subject.send(:setup_overrides, 'task', 'foo')
|
81
|
-
expect(result.
|
97
|
+
expect(result.target_list).to eq('ssh://test:22')
|
82
98
|
expect(result.user).to eq('root')
|
83
99
|
end
|
84
100
|
|
@@ -111,9 +127,9 @@ describe VagrantBolt::Runner do
|
|
111
127
|
it 'creates a shell execution' do
|
112
128
|
config.bolt_exe = 'bolt'
|
113
129
|
config.boltdir = '.'
|
114
|
-
config.
|
130
|
+
config.target_list = 'ssh://test:22'
|
115
131
|
config.finalize!
|
116
|
-
command = "bolt task run 'foo' --boltdir '.' --inventoryfile '#{inventory_path}' --
|
132
|
+
command = "bolt task run 'foo' --boltdir '.' --inventoryfile '#{inventory_path}' --targets 'ssh://test:22'"
|
117
133
|
expect(Vagrant::Util::Subprocess).to receive(:execute).with('bash', '-c', command, options).and_return(subprocess_result)
|
118
134
|
subject.run('task', 'foo')
|
119
135
|
end
|
data/spec/unit/util/bolt_spec.rb
CHANGED
@@ -39,7 +39,7 @@ describe VagrantBolt::Util::Bolt do
|
|
39
39
|
},
|
40
40
|
"transport" => "ssh",
|
41
41
|
},
|
42
|
-
"
|
42
|
+
"uri" => "ssh://machine:22",
|
43
43
|
"facts" => { 'a' => 'b' },
|
44
44
|
"vars" => { 'foo' => 'bar' },
|
45
45
|
"features" => ['foo'],
|
@@ -48,8 +48,9 @@ describe VagrantBolt::Util::Bolt do
|
|
48
48
|
let(:config_hash) { { 'config' => { 'a' => 'b' } } }
|
49
49
|
let(:node_hash) do
|
50
50
|
{
|
51
|
-
'
|
51
|
+
'targets' => [machine_hash],
|
52
52
|
'config' => config_hash['config'],
|
53
|
+
'version' => 2,
|
53
54
|
}
|
54
55
|
end
|
55
56
|
before(:each) do
|
@@ -70,7 +71,7 @@ describe VagrantBolt::Util::Bolt do
|
|
70
71
|
allow(env).to receive_message_chain("vagrantfile.config.bolt.inventory_config").and_return(config_hash)
|
71
72
|
allow(env).to receive(:active_machines).and_return(['machine'])
|
72
73
|
allow(env).to receive(:machine).and_return(machine)
|
73
|
-
allow_any_instance_of(VagrantBolt::Util::Machine).to receive(:
|
74
|
+
allow_any_instance_of(VagrantBolt::Util::Machine).to receive(:machines_in_environment).with(env).and_return([machine])
|
74
75
|
allow_any_instance_of(VagrantBolt::Util::Machine).to receive(:running?).with(machine).and_return(true)
|
75
76
|
end
|
76
77
|
|
@@ -95,7 +96,7 @@ describe VagrantBolt::Util::Bolt do
|
|
95
96
|
config.node_list = 'ssh://test:22'
|
96
97
|
config.user = 'user'
|
97
98
|
config.finalize!
|
98
|
-
expected = "bolt task run 'foo' --user \'user\' --inventoryfile '#{inventory_path}' --
|
99
|
+
expected = "bolt task run 'foo' --user \'user\' --inventoryfile '#{inventory_path}' --targets \'ssh://test:22\'"
|
99
100
|
expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
|
100
101
|
end
|
101
102
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-bolt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarret Lavallee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " Vagrant provisioning with Puppet Bolt\n"
|
14
14
|
email:
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.7.6
|
107
|
+
rubygems_version: 2.7.6.2
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Vagrant provisioning with Puppet Bolt
|