vagrant-bolt 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +0 -8
- data/.travis.yml +2 -2
- data/CHANGELOG.md +66 -0
- data/Gemfile +5 -3
- data/Puppetfile +0 -2
- data/README.md +36 -24
- 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/command.rb +2 -5
- data/lib/vagrant-bolt/config/bolt.rb +29 -22
- data/lib/vagrant-bolt/config/global.rb +68 -38
- data/lib/vagrant-bolt/config_builder/config.rb +61 -31
- data/lib/vagrant-bolt/config_builder/monkey_patches.rb +1 -1
- data/lib/vagrant-bolt/config_builder/provisioner.rb +28 -4
- data/lib/vagrant-bolt/runner.rb +10 -10
- data/lib/vagrant-bolt/util/bolt.rb +8 -7
- data/lib/vagrant-bolt/util/config.rb +15 -2
- data/lib/vagrant-bolt/util/machine.rb +1 -1
- data/lib/vagrant-bolt/version.rb +1 -1
- data/spec/unit/config/bolt_spec.rb +4 -0
- data/spec/unit/config/global_spec.rb +7 -2
- data/spec/unit/runner/runner_spec.rb +32 -17
- data/spec/unit/util/bolt_spec.rb +10 -5
- data/tasks/changelog.rake +8 -0
- metadata +5 -3
@@ -9,12 +9,24 @@ class VagrantBolt::Config::Global < Vagrant.plugin('2', :config)
|
|
9
9
|
# @return [String] The bolt working directory. Defaults to `.`
|
10
10
|
attr_accessor :boltdir
|
11
11
|
|
12
|
+
# @!attribute [rw] host_key_check
|
13
|
+
# @return [String] If the connection should check the host key on the remote host (linux)
|
14
|
+
attr_accessor :connect_timeout
|
15
|
+
|
12
16
|
# @!attribute [rw] host_key_check
|
13
17
|
# @return [Boolean] If the connection should check the host key on the remote host (linux)
|
14
18
|
attr_accessor :host_key_check
|
15
19
|
|
20
|
+
# @!attribute [rw] machine_alias
|
21
|
+
# @return [String] The alias of the machine to set in the bolt inventory
|
22
|
+
attr_accessor :machine_alias
|
23
|
+
|
24
|
+
# @!attribute [rw] machine_name
|
25
|
+
# @return [String] The name of the machine to set in the bolt inventory
|
26
|
+
attr_accessor :machine_name
|
27
|
+
|
16
28
|
# @!attribute [rw] modulepath
|
17
|
-
# @return [String] The path to the modules.
|
29
|
+
# @return [String] The path to the modules.
|
18
30
|
attr_accessor :modulepath
|
19
31
|
|
20
32
|
# @!attribute [rw] user
|
@@ -74,45 +86,60 @@ class VagrantBolt::Config::Global < Vagrant.plugin('2', :config)
|
|
74
86
|
attr_accessor :features
|
75
87
|
|
76
88
|
def initialize
|
77
|
-
@bolt_exe
|
78
|
-
@boltdir
|
79
|
-
@
|
80
|
-
@
|
81
|
-
@
|
82
|
-
@
|
83
|
-
@
|
84
|
-
@
|
85
|
-
@
|
86
|
-
@
|
87
|
-
@
|
88
|
-
@
|
89
|
-
@
|
90
|
-
@
|
91
|
-
@
|
92
|
-
@
|
93
|
-
@
|
94
|
-
@
|
89
|
+
@bolt_exe = UNSET_VALUE
|
90
|
+
@boltdir = UNSET_VALUE
|
91
|
+
@connect_timeout = UNSET_VALUE
|
92
|
+
@host_key_check = UNSET_VALUE
|
93
|
+
@machine_alias = UNSET_VALUE
|
94
|
+
@machine_name = UNSET_VALUE
|
95
|
+
@modulepath = UNSET_VALUE
|
96
|
+
@password = UNSET_VALUE
|
97
|
+
@port = UNSET_VALUE
|
98
|
+
@private_key = UNSET_VALUE
|
99
|
+
@run_as = UNSET_VALUE
|
100
|
+
@ssl = UNSET_VALUE
|
101
|
+
@ssl_verify = UNSET_VALUE
|
102
|
+
@sudo_password = UNSET_VALUE
|
103
|
+
@tmpdir = UNSET_VALUE
|
104
|
+
@user = UNSET_VALUE
|
105
|
+
@verbose = UNSET_VALUE
|
106
|
+
@debug = UNSET_VALUE
|
107
|
+
@facts = UNSET_VALUE
|
108
|
+
@vars = UNSET_VALUE
|
109
|
+
@features = UNSET_VALUE
|
95
110
|
end
|
96
111
|
|
97
112
|
def finalize!
|
98
|
-
@bolt_exe
|
99
|
-
@boltdir
|
100
|
-
@
|
101
|
-
@
|
102
|
-
@
|
103
|
-
@
|
104
|
-
@
|
105
|
-
@
|
106
|
-
@
|
107
|
-
@
|
108
|
-
@
|
109
|
-
@
|
110
|
-
@
|
111
|
-
@
|
112
|
-
@
|
113
|
-
@
|
114
|
-
@
|
115
|
-
@
|
113
|
+
@bolt_exe = bolt_exe_path if @bolt_exe == UNSET_VALUE
|
114
|
+
@boltdir = '.' if @boltdir == UNSET_VALUE
|
115
|
+
@connect_timeout = nil if @connect_timeout == UNSET_VALUE
|
116
|
+
@host_key_check = nil if @host_key_check == UNSET_VALUE
|
117
|
+
@machine_alias = nil if @machine_alias == UNSET_VALUE
|
118
|
+
@machine_name = nil if @machine_name == UNSET_VALUE
|
119
|
+
@modulepath = nil if @modulepath == UNSET_VALUE
|
120
|
+
@port = nil if @port == UNSET_VALUE
|
121
|
+
@password = nil if @password == UNSET_VALUE
|
122
|
+
@private_key = nil if @private_key == UNSET_VALUE
|
123
|
+
@run_as = nil if @run_as == UNSET_VALUE
|
124
|
+
@ssl = nil if @ssl == UNSET_VALUE
|
125
|
+
@ssl_verify = nil if @ssl_verify == UNSET_VALUE
|
126
|
+
@sudo_password = nil if @sudo_password == UNSET_VALUE
|
127
|
+
@tmpdir = nil if @tmpdir == UNSET_VALUE
|
128
|
+
@user = nil if @user == UNSET_VALUE
|
129
|
+
@verbose = nil if @verbose == UNSET_VALUE
|
130
|
+
@debug = nil if @debug == UNSET_VALUE
|
131
|
+
@facts = nil if @facts == UNSET_VALUE
|
132
|
+
@features = nil if @features == UNSET_VALUE
|
133
|
+
@vars = nil if @vars == UNSET_VALUE
|
134
|
+
end
|
135
|
+
|
136
|
+
# Get the full path to the bolt executable
|
137
|
+
# @return [String] The path to the bolt exe
|
138
|
+
def bolt_exe_path
|
139
|
+
unless Vagrant::Util::Platform.windows?
|
140
|
+
return '/opt/puppetlabs/bin/bolt' if File.file?('/opt/puppetlabs/bin/bolt')
|
141
|
+
end
|
142
|
+
Vagrant::Util::Which.which('bolt') || 'bolt'
|
116
143
|
end
|
117
144
|
|
118
145
|
def validate(_machine)
|
@@ -127,10 +154,12 @@ class VagrantBolt::Config::Global < Vagrant.plugin('2', :config)
|
|
127
154
|
group_objects = ['facts', 'features', 'vars']
|
128
155
|
config = {}
|
129
156
|
instance_variables_hash.each do |key, value|
|
130
|
-
next if value.nil?
|
157
|
+
next if value.nil? || (value == UNSET_VALUE)
|
131
158
|
|
132
159
|
if group_objects.include?(key)
|
133
160
|
config[key] = value
|
161
|
+
elsif %r{machine_\w+}.match?(key)
|
162
|
+
config[key.sub('machine_', '')] = value
|
134
163
|
else
|
135
164
|
setting_map.each do |transport, settings|
|
136
165
|
next unless settings.include?(key)
|
@@ -154,6 +183,7 @@ class VagrantBolt::Config::Global < Vagrant.plugin('2', :config)
|
|
154
183
|
'run_as',
|
155
184
|
'port',
|
156
185
|
'private_key',
|
186
|
+
'connect_timeout',
|
157
187
|
'host_key_check',
|
158
188
|
'sudo_password',
|
159
189
|
'tmpdir',
|
@@ -20,12 +20,24 @@ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
|
|
20
20
|
# @return [Boolean] Shows debug logging
|
21
21
|
def_model_attribute :debug
|
22
22
|
|
23
|
+
# @!attribute [rw] connect_timeout
|
24
|
+
# @return [String] The timeout for the ssh connection (linux)
|
25
|
+
def_model_attribute :connect_timeout
|
26
|
+
|
23
27
|
# @!attribute [rw] host_key_check
|
24
28
|
# @return [Boolean] If the connection should check the host key on the remote host (linux)
|
25
29
|
def_model_attribute :host_key_check
|
26
30
|
|
31
|
+
# @!attribute [rw] machine_alias
|
32
|
+
# @return [String] The alias of the machine to set in the bolt inventory
|
33
|
+
def_model_attribute :machine_alias
|
34
|
+
|
35
|
+
# @!attribute [rw] machine_name
|
36
|
+
# @return [String] The name of the machine to set in the bolt inventory
|
37
|
+
def_model_attribute :machine_name
|
38
|
+
|
27
39
|
# @!attribute [rw] modulepath
|
28
|
-
# @return [String] The path to the modules.
|
40
|
+
# @return [String] The path to the modules.
|
29
41
|
def_model_attribute :modulepath
|
30
42
|
|
31
43
|
# @!attribute [rw] name
|
@@ -33,21 +45,23 @@ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
|
|
33
45
|
def_model_attribute :name
|
34
46
|
|
35
47
|
# @!attribute [rw] nodes
|
48
|
+
# DEPRECATED. Use `targets` instead.
|
36
49
|
# Note: The `node_list` will override this setting.
|
37
50
|
# @return [Array<String, Symbol>, "ALL"] The nodes to run the task or plan on.
|
38
51
|
# Valid values are an array of machine names or the string "ALL".
|
39
52
|
def_model_attribute :nodes
|
40
53
|
|
41
54
|
# @!attribute [rw] excludes
|
42
|
-
# Note: The `
|
43
|
-
# Note: This will be merged with `
|
44
|
-
# @return [Array<String, Symbol>] The
|
55
|
+
# Note: The `target_list` will override this setting.
|
56
|
+
# Note: This will be merged with `targets`, with `excludes` taking precidence.
|
57
|
+
# @return [Array<String, Symbol>] The targets to exclude from running this task or plan on.
|
45
58
|
# Valid values are an array of machine names.
|
46
59
|
def_model_attribute :excludes
|
47
60
|
|
48
61
|
# @!attribute [rw] node_list
|
62
|
+
# DEPRECATED. Use `target_list` instead.
|
49
63
|
# 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
|
64
|
+
# @return [String] The bolt node list. This defaults to the current node.
|
51
65
|
def_model_attribute :node_list
|
52
66
|
|
53
67
|
# @!attribute [rw] noop
|
@@ -94,6 +108,17 @@ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
|
|
94
108
|
# @return [Boolean] If the connection should verify SSL on with WinRM (Windows)
|
95
109
|
def_model_attribute :ssl_verify
|
96
110
|
|
111
|
+
# @!attribute [rw] targets
|
112
|
+
# Note: The `target_list` will override this setting.
|
113
|
+
# @return [Array<String, Symbol>, "ALL"] The targets to run the task or plan on.
|
114
|
+
# Valid values are an array of machine names or the string "ALL".
|
115
|
+
def_model_attribute :targets
|
116
|
+
|
117
|
+
# @!attribute [rw] target_list
|
118
|
+
# This setting overrides `targets` and needs to be in the `protocol://ipaddress:port` URI format
|
119
|
+
# @return [String] The bolt target list. This defaults to the current target.
|
120
|
+
def_model_attribute :target_list
|
121
|
+
|
97
122
|
# @!attribute [rw] tmpdir
|
98
123
|
# @return [String] The directory to upload and execute temporary files on the target
|
99
124
|
def_model_attribute :tmpdir
|
@@ -118,32 +143,37 @@ class VagrantBolt::ConfigBuilder::Config < ConfigBuilder::Model::Base
|
|
118
143
|
def to_proc
|
119
144
|
proc do |config|
|
120
145
|
bolt = config.bolt
|
121
|
-
with_attr(:args)
|
122
|
-
with_attr(:bolt_exe)
|
123
|
-
with_attr(:command)
|
124
|
-
with_attr(:boltdir)
|
125
|
-
with_attr(:debug)
|
126
|
-
with_attr(:
|
127
|
-
with_attr(:
|
128
|
-
with_attr(:
|
129
|
-
with_attr(:
|
130
|
-
with_attr(:
|
131
|
-
with_attr(:
|
132
|
-
with_attr(:
|
133
|
-
with_attr(:
|
134
|
-
with_attr(:
|
135
|
-
with_attr(:
|
136
|
-
with_attr(:
|
137
|
-
with_attr(:
|
138
|
-
with_attr(:
|
139
|
-
with_attr(:
|
140
|
-
with_attr(:
|
141
|
-
with_attr(:
|
142
|
-
with_attr(:
|
143
|
-
with_attr(:
|
144
|
-
with_attr(:
|
145
|
-
with_attr(:
|
146
|
-
with_attr(:
|
146
|
+
with_attr(:args) { |val| bolt.args = val }
|
147
|
+
with_attr(:bolt_exe) { |val| bolt.bolt_exe = val }
|
148
|
+
with_attr(:command) { |val| bolt.command = val }
|
149
|
+
with_attr(:boltdir) { |val| bolt.boltdir = val }
|
150
|
+
with_attr(:debug) { |val| bolt.debug = val }
|
151
|
+
with_attr(:connect_timeout) { |val| bolt.connect_timeout = val }
|
152
|
+
with_attr(:host_key_check) { |val| bolt.host_key_check = val }
|
153
|
+
with_attr(:machine_alias) { |val| bolt.machine_alias = val }
|
154
|
+
with_attr(:machine_name) { |val| bolt.machine_name = val }
|
155
|
+
with_attr(:modulepath) { |val| bolt.modulepath = val }
|
156
|
+
with_attr(:name) { |val| bolt.name = val }
|
157
|
+
with_attr(:nodes) { |val| bolt.nodes = val }
|
158
|
+
with_attr(:noop) { |val| bolt.noop = val }
|
159
|
+
with_attr(:excludes) { |val| bolt.excludes = val }
|
160
|
+
with_attr(:node_list) { |val| bolt.node_list = val }
|
161
|
+
with_attr(:params) { |val| bolt.params = val }
|
162
|
+
with_attr(:user) { |val| bolt.user = val }
|
163
|
+
with_attr(:password) { |val| bolt.password = val }
|
164
|
+
with_attr(:port) { |val| bolt.port = val }
|
165
|
+
with_attr(:private_key) { |val| bolt.private_key = val }
|
166
|
+
with_attr(:run_as) { |val| bolt.run_as = val }
|
167
|
+
with_attr(:sudo_password) { |val| bolt.sudo_password = val }
|
168
|
+
with_attr(:ssl) { |val| bolt.ssl = val }
|
169
|
+
with_attr(:ssl_verify) { |val| bolt.ssl_verify = val }
|
170
|
+
with_attr(:targets) { |val| bolt.targets = val }
|
171
|
+
with_attr(:target_list) { |val| bolt.target_list = val }
|
172
|
+
with_attr(:tmpdir) { |val| bolt.tmpdir = val }
|
173
|
+
with_attr(:verbose) { |val| bolt.verbose = val }
|
174
|
+
with_attr(:facts) { |val| bolt.facts = val }
|
175
|
+
with_attr(:features) { |val| bolt.features = val }
|
176
|
+
with_attr(:vars) { |val| bolt.vars = val }
|
147
177
|
end
|
148
178
|
end
|
149
179
|
# rubocop:enable Metrics/BlockLength
|
@@ -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)
|
@@ -20,12 +20,24 @@ class VagrantBolt::ConfigBuilder::Provisioner < ConfigBuilder::Model::Provisione
|
|
20
20
|
# @return [Boolean] Shows debug logging
|
21
21
|
def_model_attribute :debug
|
22
22
|
|
23
|
+
# @!attribute [rw] connect_timeout
|
24
|
+
# @return [String] The ssh connection timeout (linux)
|
25
|
+
def_model_attribute :connect_timeout
|
26
|
+
|
23
27
|
# @!attribute [rw] host_key_check
|
24
28
|
# @return [Boolean] If the connection should check the host key on the remote host (linux)
|
25
29
|
def_model_attribute :host_key_check
|
26
30
|
|
31
|
+
# @!attribute [rw] machine_alias
|
32
|
+
# @return [String] The alias of the machine to set in the bolt inventory
|
33
|
+
def_model_attribute :machine_alias
|
34
|
+
|
35
|
+
# @!attribute [rw] machine_name
|
36
|
+
# @return [String] The name of the machine to set in the bolt inventory
|
37
|
+
def_model_attribute :machine_name
|
38
|
+
|
27
39
|
# @!attribute [rw] modulepath
|
28
|
-
# @return [String] The path to the modules.
|
40
|
+
# @return [String] The path to the modules.
|
29
41
|
def_model_attribute :modulepath
|
30
42
|
|
31
43
|
# @!attribute [rw] name
|
@@ -33,6 +45,7 @@ class VagrantBolt::ConfigBuilder::Provisioner < ConfigBuilder::Model::Provisione
|
|
33
45
|
def_model_attribute :name
|
34
46
|
|
35
47
|
# @!attribute [rw] nodes
|
48
|
+
# DEPRECATED. Use `targets` instead.
|
36
49
|
# Note: The `node_list` will override this setting.
|
37
50
|
# @return [Array<String, Symbol>, "ALL"] The nodes to run the task or plan on.
|
38
51
|
# Valid values are an array of machine names or the string "ALL".
|
@@ -43,9 +56,9 @@ class VagrantBolt::ConfigBuilder::Provisioner < ConfigBuilder::Model::Provisione
|
|
43
56
|
def_model_attribute :noop
|
44
57
|
|
45
58
|
# @!attribute [rw] excludes
|
46
|
-
# Note: The `
|
47
|
-
# Note: This will be merged with `
|
48
|
-
# @return [Array<String, Symbol>] The
|
59
|
+
# Note: The `target_list` will override this setting.
|
60
|
+
# Note: This will be merged with `targets`, with `excludes` taking precidence.
|
61
|
+
# @return [Array<String, Symbol>] The targets to exclude from running this task or plan on.
|
49
62
|
# Valid values are an array of machine names.
|
50
63
|
def_model_attribute :excludes
|
51
64
|
|
@@ -94,6 +107,17 @@ class VagrantBolt::ConfigBuilder::Provisioner < ConfigBuilder::Model::Provisione
|
|
94
107
|
# @return [Boolean] If the connection should verify SSL on with WinRM (Windows)
|
95
108
|
def_model_attribute :ssl_verify
|
96
109
|
|
110
|
+
# @!attribute [rw] targets
|
111
|
+
# Note: The `target_list` will override this setting.
|
112
|
+
# @return [Array<String, Symbol>, "ALL"] The targets to run the task or plan on.
|
113
|
+
# Valid values are an array of machine names or the string "ALL".
|
114
|
+
def_model_attribute :targets
|
115
|
+
|
116
|
+
# @!attribute [rw] target_list
|
117
|
+
# This setting overrides `targets` and needs to be in the `protocol://ipaddress:port` URI format
|
118
|
+
# @return [String] The bolt target list. This defaults to the current target.
|
119
|
+
def_model_attribute :target_list
|
120
|
+
|
97
121
|
# @!attribute [rw] tmpdir
|
98
122
|
# @return [String] The directory to upload and execute temporary files on the target
|
99
123
|
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,14 +44,14 @@ 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
|
-
config.modulepath = VagrantBolt::Util::Config.
|
54
|
-
config.boltdir = VagrantBolt::Util::Config.
|
53
|
+
config.modulepath = VagrantBolt::Util::Config.relative_path(config.modulepath, @env.root_path)
|
54
|
+
config.boltdir = VagrantBolt::Util::Config.relative_path(config.boltdir, @env.root_path)
|
55
55
|
|
56
56
|
config
|
57
57
|
end
|
@@ -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
|
@@ -64,18 +64,19 @@ module VagrantBolt::Util
|
|
64
64
|
ssh_info = machine.ssh_info
|
65
65
|
return node_hash if ssh_info.nil?
|
66
66
|
|
67
|
-
node_hash['alias'] = machine.name.to_s
|
68
67
|
machine_config = machine.config.bolt.inventory_config
|
69
68
|
node_hash['config'] = {}
|
70
69
|
transport = VagrantBolt::Util::Machine.windows?(machine) ? 'winrm' : 'ssh'
|
71
70
|
node_hash['config'][transport] = machine_transport_hash(machine, machine_config, ssh_info).compact
|
72
71
|
node_hash['config']['transport'] = transport
|
73
|
-
node_hash['
|
72
|
+
node_hash['uri'] = "#{transport}://#{ssh_info[:host]}:#{node_hash['config'][transport]['port']}"
|
74
73
|
machine_config.each do |key, value|
|
75
74
|
next if key == 'config' || value.nil? || value.empty?
|
76
75
|
|
77
76
|
node_hash[key] = value
|
78
77
|
end
|
78
|
+
node_hash['name'] ||= machine.name.to_s
|
79
|
+
node_hash['alias'] = machine.name.to_s if node_hash['alias'].nil? && node_hash['name'] != machine.name.to_s
|
79
80
|
node_hash.compact
|
80
81
|
end
|
81
82
|
|
@@ -108,7 +109,7 @@ module VagrantBolt::Util
|
|
108
109
|
# @param env [Object] The environment
|
109
110
|
# @return [String] The path to the inventory file
|
110
111
|
def self.inventory_file(env)
|
111
|
-
|
112
|
+
VagrantBolt::Util::Config.relative_path('bolt_inventory.yaml', env.local_data_path)
|
112
113
|
end
|
113
114
|
|
114
115
|
# Update and write the inventory file for the current running machines
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'pathname'
|
4
|
+
|
3
5
|
module VagrantBolt::Util
|
4
6
|
module Config
|
5
7
|
# Config Utility Functions
|
@@ -30,14 +32,25 @@ module VagrantBolt::Util
|
|
30
32
|
result
|
31
33
|
end
|
32
34
|
|
33
|
-
# Convert a path to the absolute path
|
35
|
+
# Convert a path to the absolute path if it is relative
|
34
36
|
# @param path [String] The path to convert
|
35
37
|
# @param root_path [Object] The root path to append
|
36
38
|
# @return [String] The absolute path or nil if path is nil
|
37
39
|
def self.full_path(path, root_path)
|
38
40
|
return path if path.nil? || root_path.nil?
|
39
41
|
|
40
|
-
|
42
|
+
(Pathname.new path).absolute? ? path : File.expand_path(path, root_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Convert a path to the relative path from the current directory
|
46
|
+
# @param path [String] The path to convert
|
47
|
+
# @param root_path [Object] The root path to append
|
48
|
+
# @return [String] The relative path or nil if path is nil
|
49
|
+
def self.relative_path(path, root_path)
|
50
|
+
return path if path.nil?
|
51
|
+
|
52
|
+
absolute_path = Pathname.new full_path(path, root_path)
|
53
|
+
absolute_path.relative_path_from(Pathname.getwd).to_s
|
41
54
|
end
|
42
55
|
end
|
43
56
|
end
|