ohai 19.1.40 → 19.1.53

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54e67e8dc14b753dc0d38f8098d6cc929cef571fd4748e558d5aa227dcc66632
4
- data.tar.gz: d6486dcf95217eea8fcc600ce98b9f8853b50eec297ccbed4179cf05aa4fe840
3
+ metadata.gz: 2d425b09ec101db36c3570531d22dd0e3b18b45d98cdd6b3c1ff934967805674
4
+ data.tar.gz: 4c115002582fa66694fd41bf168df0931ad6079438f49b79a7a46187b63a1242
5
5
  SHA512:
6
- metadata.gz: c6725323990d51b095dc2cea98561a2d00b27edc87f705332d697c0700d914661baf2ebd8924a4447777e6ea7d298838c0d267653ed14f85a9d4baa45110d3cf
7
- data.tar.gz: e0c0461bf4397107da0d0f85bf5fa8668038683abf31ebdb4965374a51f289b24aa47942fc87829860589d2960c252dec2b75ce48ff7d3c04dc2fbf25f5902f1
6
+ metadata.gz: 1420003e15080bd211c361e70cfa5a191ed76355941e513d7dced3351fa1b6a080cb20f662b769d2512ffdb36d511f1f973dfef7223b2fded76042a97cb66b30
7
+ data.tar.gz: 157296c8673458d8f1cdd3626b6e423e485b18ceb8e3a85edc2b5cf8da326ed096313b05025f268932f744232590edecb6fce1774b8f779f8466bd23a9de19dc
data/Gemfile CHANGED
@@ -11,7 +11,6 @@ gem "chef-utils", git: "https://github.com/chef/chef", branch: "main", glob: "ch
11
11
  gem "ffi", "~> 1.17", force_ruby_platform: true
12
12
  # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
13
13
  group :development do
14
- gem "cookstyle", ">= 7.32.8"
15
14
  gem "ipaddr_extensions"
16
15
  gem "rake", ">= 10.1.0"
17
16
  gem "rspec-collection_matchers", "~> 1.0"
@@ -20,6 +19,16 @@ group :development do
20
19
  gem "rspec-mocks", "~> 3.0"
21
20
  end
22
21
 
22
+ # cookstyle (and its rubocop dependency) is only needed for `rake style` and
23
+ # is intentionally kept out of :development so `bundle install --without lint`
24
+ # (used by the unit test CI job) doesn't need to resolve it. This avoids a
25
+ # transitive unicode-display_width version conflict between rubocop and
26
+ # other gems (e.g. via chef-licensing/inspec-core) that can occur on some
27
+ # platforms/gem index states.
28
+ group :lint do
29
+ gem "cookstyle", ">= 7.32.8"
30
+ end
31
+
23
32
  group :debug do
24
33
  gem "pry"
25
34
  gem "pry-byebug"
data/lib/ohai/loader.rb CHANGED
@@ -66,10 +66,11 @@ module Ohai
66
66
  collect_v7_plugins
67
67
  end
68
68
 
69
- # load additional plugins classes from a given directory
70
- # @param from [String] path to a directory with additional plugins to load
71
- def load_additional(from)
72
- from = [ Ohai.config[:plugin_path], from].flatten
69
+ # load additional plugin classes from one or more directories
70
+ # @param from [Array, String] paths to directories with additional plugins
71
+ # @param include_default [Boolean] whether to include configured paths
72
+ def load_additional(from, include_default: true)
73
+ from = [ Ohai.config[:plugin_path], from].flatten if include_default
73
74
  plugin_files_by_dir(from).collect do |plugin_file|
74
75
  logger.trace "Loading additional plugin: #{plugin_file}"
75
76
  load_v7_plugin(load_plugin_class(plugin_file))
@@ -27,7 +27,7 @@ Ohai.plugin(:Hostnamectl) do
27
27
  if hostnamectl_path
28
28
  re = /[^\p{ASCII}]/u
29
29
 
30
- shell_out(hostnamectl_path).stdout.split("\n").each do |line|
30
+ shell_out(hostnamectl_path).stdout.dup.force_encoding("UTF-8").scrub.split("\n").each do |line|
31
31
  key, val = line.split(": ", 2)
32
32
 
33
33
  key = key.chomp.lstrip.tr(" ", "_").downcase
@@ -36,6 +36,18 @@ Ohai.plugin(:RootGroup) do
36
36
  end
37
37
 
38
38
  collect_data(:default) do
39
- root_group Etc.getgrgid(Etc.getpwnam("root").gid).name
39
+ if target_mode?
40
+ # ponytail: Etc.* below always queries the *local* controller's
41
+ # passwd/group db, which is wrong in Target Mode -- it silently
42
+ # returns the controller's root group (e.g. "wheel" on macOS) instead
43
+ # of the target's, breaking any recipe relying on node["root_group"]
44
+ # downstream (e.g. chef's hostname/ssh_known_hosts_entry resources).
45
+ # `id -gn root` is supported cross-platform (AIX, Linux, BSD, etc.)
46
+ # and runs via Train against the actual target.
47
+ result = transport_connection.run_command("id -gn root")
48
+ root_group result.stdout.strip if result.exit_status == 0 && !result.stdout.strip.empty?
49
+ else
50
+ root_group Etc.getgrgid(Etc.getpwnam("root").gid).name
51
+ end
40
52
  end
41
53
  end
data/lib/ohai/system.rb CHANGED
@@ -66,6 +66,7 @@ module Ohai
66
66
  def reset_system
67
67
  @data = Mash.new
68
68
  @provides_map = ProvidesMap.new
69
+ @plugins_ran = false
69
70
 
70
71
  configure_ohai
71
72
  configure_logging if @cli
@@ -103,6 +104,25 @@ module Ohai
103
104
 
104
105
  load_plugins
105
106
  run_plugins(true, attribute_filter)
107
+ @plugins_ran = true
108
+ end
109
+
110
+ # Add a platform-selected plugin directory before the next plugin run.
111
+ #
112
+ # @param path [String] directory containing additional Ohai plugins
113
+ # @return [Boolean] true when the path was newly added
114
+ def add_platform_plugin_path(path)
115
+ path = File.expand_path(path)
116
+ return false unless Dir.exist?(path)
117
+ return false if Ohai.config[:plugin_path].include?(path)
118
+
119
+ Ohai.config[:plugin_path] << path
120
+ true
121
+ end
122
+
123
+ # @return [Boolean] whether a plugin run has completed for this system
124
+ def plugins_ran?
125
+ @plugins_ran
106
126
  end
107
127
 
108
128
  # load all plugins by calling Ohai::Loader.load_all
@@ -154,8 +174,9 @@ module Ohai
154
174
  #
155
175
  # @return [void]
156
176
  #
157
- def run_additional_plugins(plugin_path)
158
- @loader.load_additional(plugin_path).each do |plugin|
177
+ def run_additional_plugins(plugin_path, include_default: true)
178
+ paths = include_default ? [Ohai.config[:plugin_path], plugin_path].flatten : Array(plugin_path)
179
+ @loader.load_additional(paths, include_default: false).each do |plugin|
159
180
  logger.trace "Running plugin #{plugin}"
160
181
  runner.run_plugin(plugin)
161
182
  end
@@ -163,6 +184,31 @@ module Ohai
163
184
  freeze_strings!
164
185
  end
165
186
 
187
+ # Return platform attributes exposed by the target transport before the
188
+ # full Ohai run. This lets Chef select platform-specific plugins early
189
+ # enough to replace host-only collectors.
190
+ #
191
+ # @return [Hash]
192
+ def target_platform_attributes
193
+ connection = transport_connection
194
+ return {} unless connection && connection.respond_to?(:platform)
195
+
196
+ platform = connection.platform
197
+ platform_name = scalar_platform_value(platform_value(platform, :name))
198
+ platform_name ||= scalar_platform_value(platform_value(platform, :platform))
199
+ platform_name ||= scalar_platform_value(platform_value(platform, :os))
200
+ platform_name ||= platform if platform.is_a?(String) || platform.is_a?(Symbol)
201
+
202
+ attributes = {}
203
+ attributes[:platform] = platform_name unless platform_name.nil?
204
+ attributes[:platform_family] = platform_value(platform, :family)
205
+ attributes[:os] = platform_value(platform, :os) || platform_name
206
+ attributes.delete_if { |_key, value| value.nil? || value.to_s.empty? }
207
+ rescue StandardError => e
208
+ logger.debug("Unable to read target platform attributes from transport: #{e.class}: #{e.message}")
209
+ {}
210
+ end
211
+
166
212
  #
167
213
  # Serialize this object as a hash
168
214
  #
@@ -254,5 +300,24 @@ module Ohai
254
300
 
255
301
  CGI.parse(uri.query).map { |k, v| [k.to_sym, v.first] }.to_h
256
302
  end
303
+
304
+ def platform_value(platform, attribute)
305
+ value = platform.public_send(attribute) if platform.respond_to?(attribute)
306
+ if value.nil? && platform.respond_to?(:[])
307
+ begin
308
+ value = platform[attribute]
309
+ value = platform[attribute.to_s] if value.nil?
310
+ rescue IndexError, NameError, TypeError
311
+ value = nil
312
+ end
313
+ end
314
+ return nil if value.nil? || value.to_s.empty? || value.to_s == "unknown"
315
+
316
+ value
317
+ end
318
+
319
+ def scalar_platform_value(value)
320
+ value if value.is_a?(String) || value.is_a?(Symbol)
321
+ end
257
322
  end
258
323
  end
data/lib/ohai/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
 
20
20
  module Ohai
21
21
  OHAI_ROOT = File.expand_path(__dir__)
22
- VERSION = "19.1.40"
22
+ VERSION = "19.1.53"
23
23
  end
data/ohai.gemspec CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency "chef-config", ">= 14.12", "< 20"
19
19
  s.add_dependency "chef-utils", ">= 16.0", "< 20"
20
20
  s.add_dependency "ffi", ">= 1.15.5"
21
- s.add_dependency "ffi-yajl", ">= 2.2", "< 3.0"
21
+ # ffi-yajl has a stale version in 3.0.0 specifically that is in use. 3.0.1 and higher is ok again
22
+ s.add_dependency "ffi-yajl", ">= 2.2", "< 4.0", "!= 3.0.0"
22
23
  s.add_dependency "ipaddress"
23
24
  s.add_dependency "mixlib-cli", ">= 1.7.0" # 1.7+ needed to support passing multiple options
24
25
  s.add_dependency "mixlib-config", ">= 2.0", "< 4.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 19.1.40
4
+ version: 19.1.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-24 00:00:00.000000000 Z
11
+ date: 2026-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -87,7 +87,10 @@ dependencies:
87
87
  version: '2.2'
88
88
  - - "<"
89
89
  - !ruby/object:Gem::Version
90
- version: '3.0'
90
+ version: '4.0'
91
+ - - "!="
92
+ - !ruby/object:Gem::Version
93
+ version: 3.0.0
91
94
  type: :runtime
92
95
  prerelease: false
93
96
  version_requirements: !ruby/object:Gem::Requirement
@@ -97,7 +100,10 @@ dependencies:
97
100
  version: '2.2'
98
101
  - - "<"
99
102
  - !ruby/object:Gem::Version
100
- version: '3.0'
103
+ version: '4.0'
104
+ - - "!="
105
+ - !ruby/object:Gem::Version
106
+ version: 3.0.0
101
107
  - !ruby/object:Gem::Dependency
102
108
  name: ipaddress
103
109
  requirement: !ruby/object:Gem::Requirement
@@ -406,7 +412,7 @@ homepage: https://github.com/chef/ohai/
406
412
  licenses:
407
413
  - Apache-2.0
408
414
  metadata: {}
409
- post_install_message:
415
+ post_install_message:
410
416
  rdoc_options: []
411
417
  require_paths:
412
418
  - lib
@@ -422,7 +428,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
422
428
  version: '0'
423
429
  requirements: []
424
430
  rubygems_version: 3.3.27
425
- signing_key:
431
+ signing_key:
426
432
  specification_version: 4
427
433
  summary: Ohai profiles your system and emits JSON
428
434
  test_files: []