puppet 6.21.1 → 6.22.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +24 -18
  4. data/ext/project_data.yaml +2 -2
  5. data/lib/puppet/application/ssl.rb +11 -0
  6. data/lib/puppet/defaults.rb +22 -2
  7. data/lib/puppet/environments.rb +16 -1
  8. data/lib/puppet/face/facts.rb +128 -30
  9. data/lib/puppet/file_system/memory_file.rb +8 -1
  10. data/lib/puppet/file_system/windows.rb +2 -0
  11. data/lib/puppet/functions/partition.rb +8 -0
  12. data/lib/puppet/indirector/facts/facter.rb +24 -3
  13. data/lib/puppet/network/formats.rb +67 -0
  14. data/lib/puppet/network/http/factory.rb +4 -0
  15. data/lib/puppet/provider/package/dnfmodule.rb +1 -1
  16. data/lib/puppet/provider/service/systemd.rb +1 -1
  17. data/lib/puppet/provider/user/useradd.rb +1 -1
  18. data/lib/puppet/settings/environment_conf.rb +1 -0
  19. data/lib/puppet/util/fact_dif.rb +36 -17
  20. data/lib/puppet/util/monkey_patches.rb +7 -0
  21. data/lib/puppet/util/windows/adsi.rb +46 -0
  22. data/lib/puppet/util/windows/api_types.rb +1 -1
  23. data/lib/puppet/util/windows/principal.rb +9 -2
  24. data/lib/puppet/util/windows/sid.rb +4 -2
  25. data/lib/puppet/version.rb +1 -1
  26. data/locales/puppet.pot +139 -87
  27. data/man/man5/puppet.conf.5 +11 -3
  28. data/man/man8/puppet-agent.8 +1 -1
  29. data/man/man8/puppet-apply.8 +1 -1
  30. data/man/man8/puppet-catalog.8 +1 -1
  31. data/man/man8/puppet-config.8 +1 -1
  32. data/man/man8/puppet-describe.8 +1 -1
  33. data/man/man8/puppet-device.8 +1 -1
  34. data/man/man8/puppet-doc.8 +1 -1
  35. data/man/man8/puppet-epp.8 +1 -1
  36. data/man/man8/puppet-facts.8 +60 -2
  37. data/man/man8/puppet-filebucket.8 +1 -1
  38. data/man/man8/puppet-generate.8 +1 -1
  39. data/man/man8/puppet-help.8 +1 -1
  40. data/man/man8/puppet-key.8 +1 -1
  41. data/man/man8/puppet-lookup.8 +1 -1
  42. data/man/man8/puppet-man.8 +1 -1
  43. data/man/man8/puppet-module.8 +1 -1
  44. data/man/man8/puppet-node.8 +1 -1
  45. data/man/man8/puppet-parser.8 +1 -1
  46. data/man/man8/puppet-plugin.8 +1 -1
  47. data/man/man8/puppet-report.8 +1 -1
  48. data/man/man8/puppet-resource.8 +1 -1
  49. data/man/man8/puppet-script.8 +1 -1
  50. data/man/man8/puppet-ssl.8 +5 -1
  51. data/man/man8/puppet-status.8 +1 -1
  52. data/man/man8/puppet.8 +2 -2
  53. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services_vendor_preset +9 -0
  54. data/spec/integration/application/plugin_spec.rb +1 -1
  55. data/spec/integration/http/client_spec.rb +12 -0
  56. data/spec/integration/indirector/direct_file_server_spec.rb +1 -3
  57. data/spec/integration/util/windows/adsi_spec.rb +18 -0
  58. data/spec/integration/util/windows/principal_spec.rb +21 -0
  59. data/spec/integration/util/windows/registry_spec.rb +6 -0
  60. data/spec/spec_helper.rb +11 -1
  61. data/spec/unit/application/facts_spec.rb +482 -3
  62. data/spec/unit/application/ssl_spec.rb +23 -0
  63. data/spec/unit/defaults_spec.rb +16 -0
  64. data/spec/unit/environments_spec.rb +164 -88
  65. data/spec/unit/face/facts_spec.rb +4 -0
  66. data/spec/unit/file_system_spec.rb +9 -0
  67. data/spec/unit/indirector/facts/facter_spec.rb +95 -0
  68. data/spec/unit/network/formats_spec.rb +41 -0
  69. data/spec/unit/network/http/factory_spec.rb +19 -0
  70. data/spec/unit/provider/package/dnfmodule_spec.rb +10 -1
  71. data/spec/unit/provider/service/systemd_spec.rb +11 -0
  72. data/spec/unit/provider/user/useradd_spec.rb +18 -3
  73. data/spec/unit/resource/catalog_spec.rb +1 -1
  74. data/spec/unit/util/windows/sid_spec.rb +6 -0
  75. metadata +4 -6
  76. data/spec/lib/matchers/include.rb +0 -27
  77. data/spec/lib/matchers/include_spec.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a276ad05a056a465b7a0a2c8a3c6e8ca1027a12614be90761c61c884237aefc8
4
- data.tar.gz: 69bc653c7fcf75a6893083bd7fe216d8628e9f03e5a1ded3567f0f8f94891e8d
3
+ metadata.gz: a807e1e8a70b658cf3b5a430ef99e3cdea58da2ea4c0854c23c7fcf1ae8bd0c3
4
+ data.tar.gz: 37fb5485826b52ce246a27c9b2c5c79df4b281743842a33a087692e4b429abdc
5
5
  SHA512:
6
- metadata.gz: 7e0ff67c06a24ed7a113c00b3fb60da8258940b8bf7642fa37bfd562200b169a928d7d0d8b35c6019f88f5155042c39f2bb3a3647ae8bd32e8472d83fa0139c5
7
- data.tar.gz: 335aa790b52bf6c92f866c056f8b3103b583828d3c9face8a375c0488e683dd82bd51e2eaca88ec1c95e21291ce0781a5091e57d6eb92c5f86a2d7800f1a3cbb
6
+ metadata.gz: bdf22c7e19c448567811224ff61b29928894296ad31b24741083a29bddc0197e60e177576c20e76fd3fb983da968fb19d3d8c225657dc5071e610b406155460c
7
+ data.tar.gz: d50e5a0ce643431eb1d09ac77f67d1a3cca01f0044b822898cdc23b21d52713958cad91f0f185535f1025437a715797de4c2fdabf8c512c9f4b155fe7ee9b3ee
data/Gemfile CHANGED
@@ -56,7 +56,7 @@ group(:development, optional: true) do
56
56
  gem 'memory_profiler', require: false, platforms: [:mri]
57
57
  gem 'pry', require: false, platforms: [:ruby]
58
58
  gem "racc", "1.4.9", require: false, platforms: [:ruby]
59
- if RUBY_PLATFORM != 'java'
59
+ if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.5
60
60
  gem 'ruby-prof', '>= 0.16.0', require: false
61
61
  end
62
62
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,18 @@
1
+ GIT
2
+ remote: git://github.com/ciprianbadescu/packaging
3
+ revision: 5f8d2bda941abfeeb8fb1731c9b1dd4d108f5d33
4
+ branch: maint/windows-signing
5
+ specs:
6
+ packaging (0.99.49.171.g5f8d2bd)
7
+ artifactory (~> 2)
8
+ csv (= 3.1.5)
9
+ rake (>= 12.3)
10
+ release-metrics
11
+
1
12
  PATH
2
13
  remote: .
3
14
  specs:
4
- puppet (6.21.1)
15
+ puppet (6.22.1)
5
16
  CFPropertyList (~> 2.2)
6
17
  concurrent-ruby (~> 1.0)
7
18
  deep_merge (~> 1.0)
@@ -29,11 +40,11 @@ GEM
29
40
  deep_merge (1.2.1)
30
41
  diff-lcs (1.4.4)
31
42
  docopt (0.6.1)
32
- facter (4.0.51)
43
+ facter (4.1.1)
33
44
  hocon (~> 1.3)
34
45
  thor (>= 1.0.1, < 2.0)
35
46
  fast_gettext (1.1.2)
36
- ffi (1.14.2)
47
+ ffi (1.15.0)
37
48
  gettext (3.2.9)
38
49
  locale (>= 2.0.5)
39
50
  text (>= 1.3.0)
@@ -42,11 +53,11 @@ GEM
42
53
  gettext (>= 3.0.2, < 3.3.0)
43
54
  locale
44
55
  hashdiff (1.0.1)
45
- hiera (3.6.0)
46
- hiera-eyaml (3.2.0)
47
- highline (~> 1.6.19)
56
+ hiera (3.7.0)
57
+ hiera-eyaml (3.2.1)
58
+ highline
48
59
  optimist
49
- highline (1.6.21)
60
+ highline (2.0.3)
50
61
  hocon (1.3.1)
51
62
  hpricot (0.8.6)
52
63
  httpclient (2.8.3)
@@ -60,22 +71,17 @@ GEM
60
71
  multi_json (1.15.0)
61
72
  mustache (1.1.1)
62
73
  optimist (3.0.1)
63
- packaging (0.99.75)
64
- artifactory (~> 2)
65
- csv (= 3.1.5)
66
- rake (>= 12.3)
67
- release-metrics
68
74
  parallel (1.20.1)
69
75
  parser (2.7.2.0)
70
76
  ast (~> 2.4.1)
71
77
  powerpack (0.1.3)
72
- pry (0.14.0)
78
+ pry (0.14.1)
73
79
  coderay (~> 1.1)
74
80
  method_source (~> 1.0)
75
81
  public_suffix (4.0.6)
76
82
  puppet-resource_api (1.8.13)
77
83
  hocon (>= 1.0)
78
- puppetserver-ca (1.9.1)
84
+ puppetserver-ca (1.9.4)
79
85
  facter (>= 2.0.1, < 5)
80
86
  racc (1.4.9)
81
87
  rainbow (2.2.2)
@@ -86,7 +92,7 @@ GEM
86
92
  release-metrics (1.1.0)
87
93
  csv
88
94
  docopt
89
- rexml (3.2.4)
95
+ rexml (3.2.5)
90
96
  ronn (0.7.3)
91
97
  hpricot (>= 0.8.2)
92
98
  mustache (>= 0.7.0)
@@ -116,14 +122,14 @@ GEM
116
122
  unicode-display_width (~> 1.0, >= 1.0.1)
117
123
  rubocop-i18n (1.2.0)
118
124
  rubocop (~> 0.49.0)
119
- ruby-prof (1.4.2)
125
+ ruby-prof (1.4.3)
120
126
  ruby-progressbar (1.11.0)
121
127
  semantic_puppet (1.0.3)
122
128
  text (1.3.1)
123
129
  thor (1.1.0)
124
130
  unicode-display_width (1.7.0)
125
131
  vcr (5.1.0)
126
- webmock (3.11.2)
132
+ webmock (3.12.2)
127
133
  addressable (>= 2.3.6)
128
134
  crack (>= 0.3.2)
129
135
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -142,7 +148,7 @@ DEPENDENCIES
142
148
  memory_profiler
143
149
  minitar (~> 0.9)
144
150
  msgpack (~> 1.2)
145
- packaging (~> 0.99)
151
+ packaging!
146
152
  pry
147
153
  puppet!
148
154
  puppet-resource_api (~> 1.5)
@@ -41,7 +41,7 @@ gem_platform_dependencies:
41
41
  gem_runtime_dependencies:
42
42
  ffi: ['> 1.9.24', '< 2']
43
43
  # win32-xxxx gems are pinned due to PUP-6445
44
- win32-dir: '= 0.4.9'
44
+ win32-dir: ['>= 0.4.9', '<= 0.7.2']
45
45
  win32-process: '= 0.7.5'
46
46
  # Use of win32-security is deprecated
47
47
  win32-security: '= 0.2.5'
@@ -51,7 +51,7 @@ gem_platform_dependencies:
51
51
  gem_runtime_dependencies:
52
52
  ffi: ['> 1.9.24', '< 2']
53
53
  # win32-xxxx gems are pinned due to PUP-6445
54
- win32-dir: '= 0.4.9'
54
+ win32-dir: ['>= 0.4.9', '<= 0.7.2']
55
55
  win32-process: '= 0.7.5'
56
56
  # Use of win32-security is deprecated
57
57
  win32-security: '= 0.2.5'
@@ -74,6 +74,9 @@ ACTIONS
74
74
  `--localca` is specified, then also remove this host's local copy of the
75
75
  CA certificate(s) and CRL bundle. if `--target CERTNAME` is specified, then
76
76
  remove the files for the specified device on this host instead of this host.
77
+
78
+ * show:
79
+ Print the full-text version of this host's certificate.
77
80
  HELP
78
81
  end
79
82
 
@@ -142,11 +145,19 @@ HELP
142
145
  end
143
146
  @machine.ensure_client_certificate
144
147
  Puppet.notice(_("Completed SSL initialization"))
148
+ when 'show'
149
+ show(certname)
145
150
  else
146
151
  raise Puppet::Error, _("Unknown action '%{action}'") % { action: action }
147
152
  end
148
153
  end
149
154
 
155
+ def show(certname)
156
+ password = @cert_provider.load_private_key_password
157
+ ssl_context = @ssl_provider.load_context(certname: certname, password: password)
158
+ puts ssl_context.client_cert.to_text
159
+ end
160
+
150
161
  def submit_request(ssl_context)
151
162
  key = @cert_provider.load_private_key(Puppet[:certname])
152
163
  unless key
@@ -58,6 +58,18 @@ module Puppet
58
58
  end
59
59
  end
60
60
 
61
+ def self.default_cadir
62
+ return "" if Puppet::Util::Platform.windows?
63
+ old_ca_dir = "#{Puppet[:ssldir]}/ca"
64
+ new_ca_dir = '/etc/puppetlabs/puppetserver/ca'
65
+
66
+ if File.exist?("#{new_ca_dir}/ca_crt.pem")
67
+ new_ca_dir
68
+ else
69
+ old_ca_dir
70
+ end
71
+ end
72
+
61
73
  ############################################################################################
62
74
  # NOTE: For information about the available values for the ":type" property of settings,
63
75
  # see the docs for Settings.define_settings
@@ -1085,6 +1097,14 @@ EOT
1085
1097
  certificate revocation checking and does not attempt to download the CRL.
1086
1098
  EOT
1087
1099
  },
1100
+ :ciphers => {
1101
+ :default => 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256',
1102
+ :type => :string,
1103
+ :desc => "The list of ciphersuites for TLS connections initiated by puppet. The
1104
+ default value is chosen to support TLS 1.0 and up, but can be made
1105
+ more restrictive if needed. The ciphersuites must be specified in OpenSSL
1106
+ format, not IANA."
1107
+ },
1088
1108
  :key_type => {
1089
1109
  :default => 'rsa',
1090
1110
  :type => :enum,
@@ -1142,7 +1162,7 @@ EOT
1142
1162
  :desc => "The name to use the Certificate Authority certificate.",
1143
1163
  },
1144
1164
  :cadir => {
1145
- :default => "$ssldir/ca",
1165
+ :default => lambda { default_cadir },
1146
1166
  :type => :directory,
1147
1167
  :desc => "The root directory for the certificate authority.",
1148
1168
  },
@@ -1760,7 +1780,7 @@ EOT
1760
1780
  },
1761
1781
  :agent_disabled_lockfile => {
1762
1782
  :default => "$statedir/agent_disabled.lock",
1763
- :type => :file,
1783
+ :type => :string,
1764
1784
  :desc => "A lock file to indicate that puppet agent runs have been administratively
1765
1785
  disabled. File contains a JSON object with state information.",
1766
1786
  },
@@ -225,6 +225,9 @@ module Puppet::Environments
225
225
  private
226
226
 
227
227
  def create_environment(name)
228
+ # interpolated modulepaths may be cached from prior environment instances
229
+ Puppet.settings.clear_environment_settings(name)
230
+
228
231
  env_symbol = name.intern
229
232
  setting_values = Puppet.settings.values(env_symbol, Puppet.settings.preferred_run_mode)
230
233
  env = Puppet::Node::Environment.create(
@@ -350,7 +353,19 @@ module Puppet::Environments
350
353
 
351
354
  # @!macro loader_list
352
355
  def list
353
- @loader.list
356
+ # Evict all that have expired, in the same way as `get`
357
+ clear_all_expired
358
+
359
+ @loader.list.map do |env|
360
+ name = env.name
361
+ old_entry = @cache[name]
362
+ if old_entry
363
+ old_entry.value
364
+ else
365
+ add_entry(name, entry(env))
366
+ env
367
+ end
368
+ end
354
369
  end
355
370
 
356
371
  # @!macro loader_search_paths
@@ -2,28 +2,20 @@ require 'puppet/indirector/face'
2
2
  require 'puppet/node/facts'
3
3
  require 'puppet/util/fact_dif'
4
4
 
5
- EXCLUDE_LIST = %w[facterversion
6
- swapfree_mb swapsize_mb
7
- load_averages\.*
8
- memory\.swap\.available_bytes memory\.swap\.capacity memory\.swap\.total_bytes
9
- memory\.swap\.used_bytes memory\.swap\.available
10
- memory\.system\.available memory\.system\.available_bytes memory\.system\.capacity memory\.swap\.used
11
- memory\.system\.total_bytes memory\.system\.used memory\.system\.used_bytes
12
- memoryfree memoryfree_mb memorysize_mb
13
- mountpoints\..* mtu_.* mountpoints\..*\.capacity
14
- networking\.interfaces\..*\.mtu networking\.mtu partitions\..*\.filesystem
15
- partitions\..*\.size_bytes partitions\..*\.mount partitions\..*\.uuid
16
- disks\..*\.size_bytes
17
- hypervisors\.lpar\.partition_number hypervisors\.xen\.privileged hypervisors\.zone\..* hypervisors\.ldom\..*
18
- processors\.speed
19
- ldom_.*
20
- boardassettag dmi\.board\.asset_tag
21
- blockdevice_.*_vendor blockdevice_.*_size
22
- system_uptime\.days system_uptime\.hours system_uptime\.seconds system_uptime\.uptime
23
- uptime_days uptime_hours uptime_seconds
24
- system_profiler\.uptime
25
- sp_uptime
26
- uptime]
5
+ EXCLUDE_LIST = %w[ ^facterversion$
6
+ ^load_averages\..*$
7
+ ^processors\.speed$
8
+ ^swapfree$ ^swapfree_mb$
9
+ ^memoryfree$ ^memoryfree_mb$
10
+ ^memory\.swap\.available_bytes$ ^memory\.swap\.used_bytes$
11
+ ^memory\.swap\.available$ ^memory\.swap\.capacity$ ^memory\.swap\.used$
12
+ ^memory\.system\.available_bytes$ ^memory\.system\.used_bytes$
13
+ ^memory\.system\.available$ ^memory\.system\.capacity$ ^memory\.system\.used$
14
+ ^mountpoints\..*\.available.*$ ^mountpoints\..*\.capacity$ ^mountpoints\..*\.used.*$
15
+ ^sp_uptime$ ^system_profiler\.uptime$
16
+ ^uptime$ ^uptime_days$ ^uptime_hours$ ^uptime_seconds$
17
+ ^system_uptime\.uptime$ ^system_uptime\.days$ ^system_uptime\.hours$ ^system_uptime\.seconds$
18
+ ]
27
19
 
28
20
  Puppet::Indirector::Face.define(:facts, '0.0.1') do
29
21
  copyright "Puppet Inc.", 2011
@@ -125,26 +117,132 @@ Puppet::Indirector::Face.define(:facts, '0.0.1') do
125
117
  $ puppet facts diff
126
118
  EOT
127
119
 
128
- render_as :json
120
+ option("--structured") do
121
+ default_to { false }
122
+ summary _("Render the different facts as structured.")
123
+ end
124
+
125
+ option("--exclude " + _("<regex>")) do
126
+ summary _("Regex used to exclude specific facts from diff.")
127
+ end
129
128
 
130
129
  when_invoked do |*args|
130
+ options = args.pop
131
+
131
132
  Puppet.settings.preferred_run_mode = :agent
132
133
  Puppet::Node::Facts.indirection.terminus_class = :facter
133
134
 
134
135
  if Puppet::Util::Package.versioncmp(Facter.value('facterversion'), '4.0.0') < 0
135
- facter3_result = Puppet::Node::Facts.indirection.find(Puppet.settings[:certname])
136
- begin
137
- require 'facter-ng'
138
- facter4_result = Puppet::Node::Facts.indirection.find(Puppet.settings[:certname])
139
- rescue LoadError
140
- raise ArgumentError, 'facter-ng could not be loaded'
136
+ cmd_flags = '--render-as json --show-legacy'
137
+
138
+ # puppet/ruby are in PATH since it was updated in the wrapper script
139
+ puppet_show_cmd = "puppet facts show"
140
+ if Puppet::Util::Platform.windows?
141
+ puppet_show_cmd = "ruby -S -- #{puppet_show_cmd}"
141
142
  end
142
- fact_diff = FactDif.new(facter3_result.to_json, facter4_result.to_json, EXCLUDE_LIST)
143
+
144
+ facter_3_result = Puppet::Util::Execution.execute("#{puppet_show_cmd} --no-facterng #{cmd_flags}", combine: false)
145
+ facter_ng_result = Puppet::Util::Execution.execute("#{puppet_show_cmd} --facterng #{cmd_flags}", combine: false)
146
+
147
+ exclude_list = options[:exclude].nil? ? EXCLUDE_LIST : EXCLUDE_LIST + [ options[:exclude] ]
148
+ fact_diff = FactDif.new(facter_3_result, facter_ng_result, exclude_list, options[:structured])
143
149
  fact_diff.difs
144
150
  else
145
151
  Puppet.warning _("Already using Facter 4. To use `puppet facts diff` remove facterng from the .conf file or run `puppet config set facterng false`.")
146
152
  exit 0
147
153
  end
148
154
  end
155
+
156
+ when_rendering :console do |result|
157
+ case result
158
+ when Array, Hash
159
+ Puppet::Util::Json.dump(result, :pretty => true)
160
+ else
161
+ result
162
+ end
163
+ end
164
+ end
165
+
166
+ action(:show) do
167
+ summary _("Retrieve current node's facts.")
168
+ arguments _("[<facts>]")
169
+ description <<-'EOT'
170
+ Reads facts from the local system using `facter` terminus.
171
+ A query can be provided to retrieve just a specific fact or a set of facts.
172
+ EOT
173
+ returns "The output of facter with added puppet specific facts."
174
+ notes <<-'EOT'
175
+
176
+ EOT
177
+ examples <<-'EOT'
178
+ retrieve facts:
179
+
180
+ $ puppet facts show os
181
+ EOT
182
+
183
+ option("--config-file " + _("<path>")) do
184
+ default_to { nil }
185
+ summary _("The location of the config file for Facter.")
186
+ end
187
+
188
+ option("--custom-dir " + _("<path>")) do
189
+ default_to { nil }
190
+ summary _("The path to a directory that contains custom facts.")
191
+ end
192
+
193
+ option("--external-dir " + _("<path>")) do
194
+ default_to { nil }
195
+ summary _("The path to a directory that contains external facts.")
196
+ end
197
+
198
+ option("--no-block") do
199
+ summary _("Disable fact blocking mechanism.")
200
+ end
201
+
202
+ option("--no-cache") do
203
+ summary _("Disable fact caching mechanism.")
204
+ end
205
+
206
+ option("--show-legacy") do
207
+ summary _("Show legacy facts when querying all facts.")
208
+ end
209
+
210
+ option("--value-only") do
211
+ summary _("Show only the value when the action is called with a single query")
212
+ end
213
+
214
+ when_invoked do |*args|
215
+ options = args.pop
216
+
217
+ Puppet.settings.preferred_run_mode = :agent
218
+ Puppet::Node::Facts.indirection.terminus_class = :facter
219
+
220
+ if options[:value_only] && !args.count.eql?(1)
221
+ options[:value_only] = nil
222
+ Puppet.warning("Incorrect use of --value-only argument; it can only be used when querying for a single fact!")
223
+ end
224
+
225
+ options[:user_query] = args
226
+ options[:resolve_options] = true
227
+ result = Puppet::Node::Facts.indirection.find(Puppet.settings[:certname], options)
228
+
229
+ if options[:value_only]
230
+ result.values.values.first
231
+ else
232
+ result.values
233
+ end
234
+ end
235
+
236
+ when_rendering :console do |result|
237
+ # VALID_TYPES = [Integer, Float, TrueClass, FalseClass, NilClass, Symbol, String, Array, Hash].freeze
238
+ # from https://github.com/puppetlabs/facter/blob/4.0.49/lib/facter/custom_facts/util/normalization.rb#L8
239
+
240
+ case result
241
+ when Array, Hash
242
+ Puppet::Util::Json.dump(result, :pretty => true)
243
+ else # one of VALID_TYPES above
244
+ result
245
+ end
246
+ end
149
247
  end
150
248
  end
@@ -7,6 +7,13 @@ class Puppet::FileSystem::MemoryFile
7
7
  new(path, :exist? => false, :executable? => false)
8
8
  end
9
9
 
10
+ def self.a_missing_directory(path)
11
+ new(path,
12
+ :exist? => false,
13
+ :executable? => false,
14
+ :directory? => true)
15
+ end
16
+
10
17
  def self.a_regular_file_containing(path, content)
11
18
  new(path, :exist? => true, :executable? => false, :content => content)
12
19
  end
@@ -18,7 +25,7 @@ class Puppet::FileSystem::MemoryFile
18
25
  def self.a_directory(path, children = [])
19
26
  new(path,
20
27
  :exist? => true,
21
- :excutable? => true,
28
+ :executable? => true,
22
29
  :directory? => true,
23
30
  :children => children)
24
31
  end