Skip to content

Commit 3e48b37

Browse files
committed
Merge branch 'pr/2158'
* pr/2158: (Maint) Fix deprecation message to point to the right alternative (#23373) Only parse section lines once (#23373) Restore 'all' functionality (Maint) Remove unused code (#23373) Don't apply all metadata (#23373) Use puppet config set in tests (#23373) Don't set metadata when it isn't supported (#23373) Check for minimal use of [main] (#23373) Reuse existing section headers (#23373) Add section control to the config print action (#23373) Pull apart settings into a few more classes (#23373) Provide a more structure config file parse (#23373) Have config parsing use IniFile's sections (#23373) Support selecting the section Closes GH-2158
2 parents ce315a1 + 69ad509 commit 3e48b37

File tree

15 files changed

+766
-351
lines changed

15 files changed

+766
-351
lines changed

acceptance/tests/face/loadable_from_modules.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@
1212
user_modulepath = get_test_file_path(agent, 'user/modules')
1313

1414
# make sure that we use the modulepath from the dev environment
15-
create_test_file(agent, 'puppet.conf', <<"END")
16-
[user]
17-
environment=dev
18-
modulepath=#{user_modulepath}
19-
20-
[dev]
21-
modulepath=#{dev_modulepath}
22-
END
2315
puppetconf = get_test_file_path(agent, 'puppet.conf')
16+
on agent, puppet("config", "set", "environment", "dev", "--section", "user", "--config", puppetconf)
17+
on agent, puppet("config", "set", "modulepath", user_modulepath, "--section", "user", "--config", puppetconf)
18+
on agent, puppet("config", "set", "modulepath", dev_modulepath, "--section", "user", "--config", puppetconf)
2419

2520
on agent, 'rm -rf puppetlabs-helloworld'
2621
on agent, puppet("module", "generate", "puppetlabs-helloworld")

lib/puppet/face/config.rb

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
summary "Interact with Puppet's configuration options."
99

10+
option "--section SECTION_NAME" do
11+
default_to { "main" }
12+
summary "The section of the configuration file to interact with."
13+
end
14+
1015
action(:print) do
1116
summary "Examine Puppet's current configuration settings."
1217
arguments "(all | <setting> [<setting> ...]"
13-
returns <<-'EOT'
14-
A single value when called with one config setting, and a list of
15-
settings and values when called with multiple options or "all."
16-
EOT
1718
description <<-'EOT'
1819
Prints the value of a single configuration option or a list of
1920
configuration options.
@@ -22,8 +23,8 @@
2223
`puppet <subcommand> --configprint`.
2324
EOT
2425
notes <<-'EOT'
25-
By default, this action reads the configuration in agent mode.
26-
Use the '--run_mode' and '--environment' flags to examine other
26+
By default, this action reads the general configuration in in the 'main'
27+
section. Use the '--section' and '--environment' flags to examine other
2728
configuration domains.
2829
EOT
2930
examples <<-'EOT'
@@ -33,16 +34,22 @@
3334
3435
Get a list of important directories from the master's config:
3536
36-
$ puppet config print all --run_mode master | grep -E "(path|dir)"
37+
$ puppet config print all --section master | grep -E "(path|dir)"
3738
EOT
3839

3940
when_invoked do |*args|
40-
args.pop
41+
options = args.pop
4142

42-
args = [ "all" ] if args.empty?
43+
args = Puppet.settings.to_a.collect(&:first) if args.empty? || args == ['all']
4344

44-
Puppet.settings[:configprint] = args.join(",")
45-
Puppet.settings.print_config_options
45+
values = Puppet.settings.values(Puppet[:environment].to_sym, options[:section].to_sym)
46+
if args.length == 1
47+
puts values.interpolate(args[0].to_sym)
48+
else
49+
args.each do |setting_name|
50+
puts "#{setting_name} = #{values.interpolate(setting_name.to_sym)}"
51+
end
52+
end
4653
nil
4754
end
4855
end
@@ -53,20 +60,27 @@
5360
description <<-'EOT'
5461
Update values in the `puppet.conf` configuration file.
5562
EOT
63+
notes <<-'EOT'
64+
By default, this action manipulates the configuration in the
65+
'main' section. Use the '--section' flag to manipulate other
66+
configuration domains.
67+
EOT
5668
examples <<-'EOT'
5769
Set puppet's runfile directory:
5870
5971
$ puppet config set rundir /var/run/puppet
60-
EOT
6172
62-
when_invoked do |*args|
63-
name, value = args
73+
Set the vardir for only the agent:
74+
75+
$ puppet config set vardir /var/lib/puppetagent --section agent
76+
EOT
6477

78+
when_invoked do |name, value, options|
6579
file = Puppet::FileSystem::File.new(Puppet.settings.which_configuration_file)
6680
file.touch
6781
file.open(nil, 'r+') do |file|
6882
Puppet::Settings::IniFile.update(file) do |config|
69-
config.set(name, value)
83+
config.set(options[:section], name, value)
7084
end
7185
end
7286
nil

lib/puppet/node/environment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def validate_dirs(dirs)
456456
def perform_initial_import
457457
return empty_parse_result if Puppet.settings[:ignoreimport]
458458
parser = Puppet::Parser::ParserFactory.parser(self)
459-
if code = Puppet.settings.uninterpolated_value(:code, name.to_s) and code != ""
459+
if code = Puppet.settings.value(:code, name.to_s) and code != ""
460460
parser.string = code
461461
parser.parse
462462
else

0 commit comments

Comments
 (0)