facter 4.8.0 → 4.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1b586ac7fd5ca2a0dbba3e314510199c246eeafcf3238d4450429c07662e2ac
4
- data.tar.gz: a3dbb666fd7d0168042df86ba3f85bd5d487a85ed348bf71fc3e0ec2f397a347
3
+ metadata.gz: 6aeed6f3058d490dd1b3e734c8d8de31efd16a275324e019e619a6084d465722
4
+ data.tar.gz: 224c4d60e9a71cbce735ee6de290949c73d949580e6e68ae16977b12fbc25517
5
5
  SHA512:
6
- metadata.gz: 2580f1bb8294a6de8e89402244448362f1657d31db3d9d4d2dba551e103848a5285983fd9f57693d4afc2ea6fd6678d97889490e82c8542d125bddb917fd7c58
7
- data.tar.gz: 8c26e42de115a8b5f3bef1b045b8aff8c18b3f28ab1ca431ea7225f71a97114f7bfaddbc9b9d5ebed7c92225a045d225582cd0d667740ab6beabdcad2c1613da
6
+ metadata.gz: 3c47aaeaf6fafa8cefe84f8e32fd5837d0a138ca6561b96fa7016f633e7fbc9920c0e0986334dd012d5adc34a2fecd281529a997f51a6af5db25bcc7a12553e9
7
+ data.tar.gz: c8af80e38871c4e5261ad91ad858c66a665a2d48094a8c1fe941cfcb4df28b20490abdba6d221fd1b10caa7e3614f04101e87f5fe983c1c8ff40846b5c025ba5
@@ -25,8 +25,8 @@ module Facter
25
25
  # set the new (temporary) value for the environment variable
26
26
  ENV[var] = value
27
27
  end
28
- # execute the caller's block, capture the return value
29
- rv = yield
28
+ # execute the caller's block, returning its value
29
+ yield
30
30
  # use an ensure block to make absolutely sure we restore the variables
31
31
  ensure
32
32
  # restore the old values
@@ -38,8 +38,6 @@ module Facter
38
38
  ENV.delete(var)
39
39
  end
40
40
  end
41
- # return the captured return value
42
- rv
43
41
  end
44
42
 
45
43
  def execute(command, options = {})
@@ -43,7 +43,7 @@ module Facter
43
43
 
44
44
  info = {}
45
45
  case container
46
- when 'lxcroot'
46
+ when 'lxc'
47
47
  vm = 'lxc'
48
48
  when 'podman'
49
49
  vm = 'podman'
@@ -54,7 +54,7 @@ module Facter
54
54
  info = { 'id' => Facter::Util::FileHelper.safe_read('/etc/machine-id', nil).strip }
55
55
  else
56
56
  vm = 'container_other'
57
- log.warn("Container runtime, '#{container}', is unsupported, setting to, '#{vm}'")
57
+ log.warn("Container runtime, '#{container}', is unsupported, setting to '#{vm}'")
58
58
  end
59
59
  @fact_list[:vm] = vm
60
60
  @fact_list[:hypervisor] = { vm.to_sym => info } if vm
@@ -68,9 +68,9 @@ module Facter
68
68
 
69
69
  def read_domain
70
70
  file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
71
- if file_content =~ /^domain\s+(\S+)/
71
+ if file_content =~ /^domain\s+([^.]\S+)/
72
72
  Regexp.last_match(1)
73
- elsif file_content =~ /^search\s+(\S+)/
73
+ elsif file_content =~ /^search\s+([^.]\S+)/
74
74
  Regexp.last_match(1)
75
75
  end
76
76
  end
@@ -96,9 +96,9 @@ module Facter
96
96
 
97
97
  def read_domain
98
98
  file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
99
- if file_content =~ /^domain\s+(\S+)/
99
+ if file_content =~ /^domain\s+([^.]\S+)/
100
100
  Regexp.last_match(1)
101
- elsif file_content =~ /^search\s+(\S+)/
101
+ elsif file_content =~ /^search\s+([^.]\S+)/
102
102
  Regexp.last_match(1)
103
103
  end
104
104
  end
@@ -69,13 +69,14 @@ module Facter
69
69
  size: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes),
70
70
  backing_file: backing_file }
71
71
  info_hash.merge!(populate_from_syscalls(partition_name, blkid_and_lsblk))
72
- @fact_list[:partitions][partition_name] = info_hash.reject { |_key, value| value.nil? }
72
+ @fact_list[:partitions][partition_name] = info_hash.compact
73
73
  end
74
74
 
75
75
  def populate_from_syscalls(partition_name, blkid_and_lsblk)
76
- part_info = populate_from_blkid(partition_name, blkid_and_lsblk)
76
+ # Prefer lsblk over blkid since lsblk does not require root, returns more information, and is recommended by blkid
77
+ part_info = populate_from_lsblk(partition_name, blkid_and_lsblk)
77
78
 
78
- return populate_from_lsblk(partition_name, blkid_and_lsblk) if part_info.empty?
79
+ return populate_from_blkid(partition_name, blkid_and_lsblk) if part_info.empty?
79
80
 
80
81
  part_info
81
82
  end
@@ -121,26 +122,47 @@ module Facter
121
122
  def populate_from_lsblk(partition_name, blkid_and_lsblk)
122
123
  return {} unless available?('lsblk', blkid_and_lsblk)
123
124
 
124
- blkid_and_lsblk[:lsblk] ||= Facter::Core::Execution.execute('lsblk -fp', logger: log)
125
+ lsblk_version_raw = Facter::Core::Execution.execute('lsblk --version 2>&1', logger: log)
126
+ # Return if the version of lsblk is too old (< 2.22) to support the --version flag
127
+ lsblk_version_raw.match?(/ \d\.\d+/) ? lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f : (return {})
125
128
 
126
- part_info = blkid_and_lsblk[:lsblk].match(/#{partition_name}.*/).to_s.split(' ')
127
- return {} if part_info.empty?
129
+ # The -p/--paths option was added in lsblk 2.23, return early and fall back to blkid with earlier versions
130
+ return {} if lsblk_version < 2.23
128
131
 
129
- parse_part_info(part_info)
130
- end
132
+ blkid_and_lsblk[:lsblk] ||= execute_and_extract_lsblk_info(lsblk_version)
131
133
 
132
- def parse_part_info(part_info)
133
- result = { filesystem: part_info[1] }
134
+ partition_data = blkid_and_lsblk[:lsblk][partition_name]
135
+ return {} unless partition_data
134
136
 
135
- if part_info.count.eql?(5)
136
- result[:label] = part_info[2]
137
- result[:uuid] = part_info[3]
138
- else
139
- result[:uuid] = part_info[2]
140
- end
137
+ filesys = partition_data['FSTYPE']
138
+ uuid = partition_data['UUID']
139
+ label = partition_data['LABEL']
140
+ part_uuid = partition_data['PARTUUID']
141
+ part_label = partition_data['PARTLABEL']
142
+ part_type = partition_data['PARTTYPE']
143
+
144
+ result = { filesystem: filesys, uuid: uuid, label: label, partuuid: part_uuid, partlabel: part_label }
145
+ result[:parttype] = part_type if part_type
141
146
 
142
147
  result
143
148
  end
149
+
150
+ def execute_and_extract_lsblk_info(lsblk_version)
151
+ # lsblk 2.25 added support for GPT partition type GUIDs
152
+ stdout = if lsblk_version >= 2.25
153
+ Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,UUID,LABEL,PARTUUID,PARTLABEL,PARTTYPE', logger: log)
154
+ else
155
+ Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID,PARTUUID,PARTLABEL', logger: log)
156
+ end
157
+
158
+ output_hash = Hash[*stdout.split(/^(NAME=\S+)/)[1..-1]]
159
+ output_hash.transform_keys! { |key| key.delete('NAME=')[1..-2] }
160
+ output_hash.each do |key, value|
161
+ output_hash[key] = Hash[*value.chomp.rstrip.split(/ ([^= ]+)=/)[1..-1].each { |x| x.delete!('"') }]
162
+ end
163
+ output_hash.each_value { |value_hash| value_hash.delete_if { |_k, v| v.empty? } }
164
+ output_hash.delete_if { |_k, v| v.empty? }
165
+ end
144
166
  end
145
167
  end
146
168
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.8.0' unless defined?(VERSION)
4
+ VERSION = '4.10.0' unless defined?(VERSION)
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-19 00:00:00.000000000 Z
11
+ date: 2024-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -1193,7 +1193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1193
1193
  - !ruby/object:Gem::Version
1194
1194
  version: '0'
1195
1195
  requirements: []
1196
- rubygems_version: 3.4.20
1196
+ rubygems_version: 3.5.19
1197
1197
  signing_key:
1198
1198
  specification_version: 4
1199
1199
  summary: Facter, a system inventory tool