Skip to content

Commit b92e16f

Browse files
authored
Merge pull request #8753 from joshcooper/write_catalog_summary_1042
(PUP-1042) Add setting for puppet apply to write catalog summary
2 parents 5d47196 + 806cefa commit b92e16f

File tree

5 files changed

+111
-60
lines changed

5 files changed

+111
-60
lines changed

lib/puppet/application/agent.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ def help
334334
specifying a time of 0.
335335
(This is a Puppet setting, and can go in puppet.conf.)
336336
337+
* --write_catalog_summary
338+
After compiling the catalog saves the resource list and classes list to the node
339+
in the state directory named classes.txt and resources.txt
340+
(This is a Puppet setting, and can go in puppet.conf.)
337341
338342
EXAMPLE
339343
-------

lib/puppet/application/apply.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class Puppet::Application::Apply < Puppet::Application
1616
option("--use-nodes")
1717
option("--detailed-exitcodes")
1818

19-
option("--write-catalog-summary")
19+
option("--write-catalog-summary") do |arg|
20+
Puppet[:write_catalog_summary] = arg
21+
end
2022

2123
option("--catalog catalog", "-c catalog") do |arg|
2224
options[:catalog] = arg
@@ -169,6 +171,7 @@ def help
169171
def app_defaults
170172
super.merge({
171173
:default_file_terminus => :file_server,
174+
:write_catalog_summary => false
172175
})
173176
end
174177

@@ -247,7 +250,22 @@ def main
247250

248251
catalog.retrieval_duration = Time.now - starttime
249252

250-
if options[:write_catalog_summary]
253+
# We accept either the global option `--write_catalog_summary`
254+
# corresponding to the new setting, or the application option
255+
# `--write-catalog-summary`. The latter is needed to maintain backwards
256+
# compatibility.
257+
#
258+
# Puppet settings parse global options using PuppetOptionParser, but it
259+
# only recognizes underscores, not dashes.
260+
# The base application parses app specific options using ruby's builtin
261+
# OptionParser. As of ruby 2.4, it will accept either underscores or
262+
# dashes, but prefer dashes.
263+
#
264+
# So if underscores are used, the PuppetOptionParser will parse it and
265+
# store that in Puppet[:write_catalog_summary]. If dashes are used,
266+
# OptionParser will parse it, and set Puppet[:write_catalog_summary]. In
267+
# either case, settings will contain the correct value.
268+
if Puppet[:write_catalog_summary]
251269
catalog.write_class_file
252270
catalog.write_resource_file
253271
end

lib/puppet/configurer.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ def convert_catalog(result, duration, facts, options = {})
118118
catalog = result.to_ral
119119
catalog.finalize
120120
catalog.retrieval_duration = duration
121-
catalog.write_class_file
122-
catalog.write_resource_file
121+
122+
if Puppet[:write_catalog_summary]
123+
catalog.write_class_file
124+
catalog.write_resource_file
125+
end
123126
end
124127
options[:report].add_times(:convert_catalog, catalog_conversion_time) if options[:report]
125128

lib/puppet/defaults.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,12 @@ def self.initialize_default_settings!(settings)
16381638
:mode => "0750",
16391639
:desc => "The directory in which serialized data is stored on the client."
16401640
},
1641+
:write_catalog_summary => {
1642+
:default => true,
1643+
:type => :boolean,
1644+
:desc => "Whether to write the `classfile` and `resourcefile` after applying
1645+
the catalog. It is enabled by default, except when running `puppet apply`.",
1646+
},
16411647
:classfile => {
16421648
:default => "$statedir/classes.txt",
16431649
:type => :file,

0 commit comments

Comments
 (0)