puppet 2.7.1 → 2.7.3

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 (171) hide show
  1. data/CHANGELOG +225 -1
  2. data/CONTRIBUTING.md +299 -0
  3. data/README.md +0 -1
  4. data/conf/redhat/puppet.spec +132 -25
  5. data/conf/solaris/pkginfo +1 -1
  6. data/conf/suse/puppet.spec +5 -2
  7. data/ext/envpuppet +56 -3
  8. data/ext/vim/README +2 -1
  9. data/ext/vim/ftplugin/puppet.vim +94 -0
  10. data/ext/vim/indent/puppet.vim +76 -0
  11. data/lib/puppet.rb +2 -3
  12. data/lib/puppet/application/agent.rb +7 -7
  13. data/lib/puppet/application/apply.rb +20 -8
  14. data/lib/puppet/application/ca.rb +5 -0
  15. data/lib/puppet/application/cert.rb +2 -1
  16. data/lib/puppet/application/certificate.rb +0 -5
  17. data/lib/puppet/application/device.rb +4 -4
  18. data/lib/puppet/application/doc.rb +23 -12
  19. data/lib/puppet/application/face_base.rb +2 -1
  20. data/lib/puppet/application/inspect.rb +5 -2
  21. data/lib/puppet/configurer.rb +60 -56
  22. data/lib/puppet/configurer/fact_handler.rb +6 -1
  23. data/lib/puppet/defaults.rb +20 -1
  24. data/lib/puppet/face/ca.rb +233 -0
  25. data/lib/puppet/face/certificate.rb +15 -11
  26. data/lib/puppet/face/certificate_request.rb +9 -11
  27. data/lib/puppet/face/certificate_revocation_list.rb +5 -7
  28. data/lib/puppet/face/node/clean.rb +154 -0
  29. data/lib/puppet/face/status.rb +1 -0
  30. data/lib/puppet/file_serving/configuration/parser.rb +6 -13
  31. data/lib/puppet/indirector/exec.rb +3 -3
  32. data/lib/puppet/indirector/face.rb +17 -7
  33. data/lib/puppet/indirector/report/processor.rb +29 -16
  34. data/lib/puppet/indirector/rest.rb +42 -7
  35. data/lib/puppet/indirector/yaml.rb +5 -0
  36. data/lib/puppet/interface.rb +7 -2
  37. data/lib/puppet/interface/action.rb +57 -23
  38. data/lib/puppet/interface/action_manager.rb +10 -5
  39. data/lib/puppet/interface/face_collection.rb +43 -52
  40. data/lib/puppet/interface/option.rb +19 -0
  41. data/lib/puppet/interface/option_builder.rb +13 -0
  42. data/lib/puppet/interface/option_manager.rb +2 -1
  43. data/lib/puppet/metatype/manager.rb +7 -20
  44. data/lib/puppet/module.rb +4 -1
  45. data/lib/puppet/network/authconfig.rb +3 -1
  46. data/lib/puppet/network/authstore.rb +14 -5
  47. data/lib/puppet/network/handler/fileserver.rb +3 -0
  48. data/lib/puppet/network/http/webrick.rb +1 -1
  49. data/lib/puppet/network/rest_authconfig.rb +6 -1
  50. data/lib/puppet/network/rest_authorization.rb +1 -1
  51. data/lib/puppet/parser/compiler.rb +8 -11
  52. data/lib/puppet/parser/functions.rb +1 -6
  53. data/lib/puppet/parser/functions/create_resources.rb +6 -5
  54. data/lib/puppet/parser/functions/regsubst.rb +26 -0
  55. data/lib/puppet/parser/functions/shellquote.rb +26 -0
  56. data/lib/puppet/parser/functions/sprintf.rb +26 -0
  57. data/lib/puppet/parser/grammar.ra +34 -60
  58. data/lib/puppet/parser/lexer.rb +5 -5
  59. data/lib/puppet/parser/parser.rb +913 -1196
  60. data/lib/puppet/parser/resource.rb +18 -1
  61. data/lib/puppet/parser/scope.rb +2 -2
  62. data/lib/puppet/provider/augeas/augeas.rb +42 -17
  63. data/lib/puppet/provider/mount/parsed.rb +19 -1
  64. data/lib/puppet/provider/naginator.rb +9 -1
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
  66. data/lib/puppet/provider/network_device.rb +1 -1
  67. data/lib/puppet/provider/package/aptitude.rb +1 -0
  68. data/lib/puppet/provider/package/pacman.rb +94 -0
  69. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
  70. data/lib/puppet/rails/host.rb +7 -0
  71. data/lib/puppet/reports/store.rb +15 -0
  72. data/lib/puppet/resource/catalog.rb +15 -6
  73. data/lib/puppet/ssl/certificate.rb +6 -0
  74. data/lib/puppet/ssl/inventory.rb +2 -0
  75. data/lib/puppet/transaction.rb +9 -17
  76. data/lib/puppet/transaction/report.rb +3 -3
  77. data/lib/puppet/type.rb +13 -24
  78. data/lib/puppet/type/file.rb +8 -2
  79. data/lib/puppet/type/file/source.rb +2 -2
  80. data/lib/puppet/type/service.rb +20 -24
  81. data/lib/puppet/type/ssh_authorized_key.rb +12 -0
  82. data/lib/puppet/type/user.rb +8 -0
  83. data/lib/puppet/util.rb +0 -1
  84. data/lib/puppet/util/network_device.rb +3 -3
  85. data/lib/puppet/util/settings.rb +1 -1
  86. data/lib/puppet/util/settings/file_setting.rb +1 -0
  87. data/lib/semver.rb +65 -0
  88. data/spec/integration/defaults_spec.rb +23 -1
  89. data/spec/integration/network/rest_authconfig_spec.rb +145 -0
  90. data/spec/integration/node/facts_spec.rb +1 -1
  91. data/spec/integration/parser/functions_spec.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +31 -0
  93. data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
  94. data/spec/integration/type_spec.rb +11 -0
  95. data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
  96. data/spec/lib/puppet/face/huzzah.rb +1 -0
  97. data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
  98. data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
  99. data/spec/unit/application/agent_spec.rb +2 -2
  100. data/spec/unit/application/apply_spec.rb +74 -56
  101. data/spec/unit/application/cert_spec.rb +10 -0
  102. data/spec/unit/application/device_spec.rb +2 -3
  103. data/spec/unit/application/face_base_spec.rb +1 -0
  104. data/spec/unit/application/facts_spec.rb +1 -0
  105. data/spec/unit/application/inspect_spec.rb +5 -0
  106. data/spec/unit/configurer/fact_handler_spec.rb +45 -37
  107. data/spec/unit/configurer_spec.rb +405 -327
  108. data/spec/unit/face/ca_spec.rb +355 -0
  109. data/spec/unit/face/certificate_spec.rb +16 -4
  110. data/spec/unit/face/node_spec.rb +261 -1
  111. data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
  112. data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
  113. data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
  114. data/spec/unit/indirector/exec_spec.rb +4 -4
  115. data/spec/unit/indirector/face_spec.rb +3 -1
  116. data/spec/unit/indirector/facts/couch_spec.rb +2 -2
  117. data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
  118. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  119. data/spec/unit/indirector/report/processor_spec.rb +31 -8
  120. data/spec/unit/indirector/rest_spec.rb +53 -5
  121. data/spec/unit/indirector/yaml_spec.rb +18 -0
  122. data/spec/unit/interface/action_spec.rb +112 -8
  123. data/spec/unit/interface/face_collection_spec.rb +46 -36
  124. data/spec/unit/interface/option_spec.rb +44 -0
  125. data/spec/unit/interface_spec.rb +11 -6
  126. data/spec/unit/module_spec.rb +38 -9
  127. data/spec/unit/network/authconfig_spec.rb +23 -0
  128. data/spec/unit/network/authstore_spec.rb +36 -4
  129. data/spec/unit/network/handler/fileserver_spec.rb +32 -0
  130. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  131. data/spec/unit/node_spec.rb +1 -0
  132. data/spec/unit/parser/compiler_spec.rb +8 -46
  133. data/spec/unit/parser/lexer_spec.rb +27 -17
  134. data/spec/unit/parser/resource_spec.rb +61 -3
  135. data/spec/unit/parser/scope_spec.rb +5 -1
  136. data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
  137. data/spec/unit/provider/cisco_spec.rb +3 -4
  138. data/spec/unit/provider/interface/cisco_spec.rb +1 -2
  139. data/spec/unit/provider/mount/parsed_spec.rb +41 -0
  140. data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
  141. data/spec/unit/provider/network_device_spec.rb +1 -2
  142. data/spec/unit/provider/package/pacman_spec.rb +237 -0
  143. data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
  144. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
  145. data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
  146. data/spec/unit/rails/host_spec.rb +8 -0
  147. data/spec/unit/resource/catalog_spec.rb +55 -8
  148. data/spec/unit/semver_spec.rb +187 -0
  149. data/spec/unit/ssl/certificate_spec.rb +25 -0
  150. data/spec/unit/transaction/report_spec.rb +3 -3
  151. data/spec/unit/transaction_spec.rb +8 -2
  152. data/spec/unit/type/file_spec.rb +57 -0
  153. data/spec/unit/type/interface_spec.rb +1 -2
  154. data/spec/unit/type/schedule_spec.rb +73 -42
  155. data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
  156. data/spec/unit/type/user_spec.rb +8 -0
  157. data/spec/unit/type/vlan_spec.rb +1 -2
  158. data/spec/unit/type_spec.rb +66 -0
  159. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
  160. data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
  161. data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
  162. data/spec/unit/util/network_device/config_spec.rb +3 -4
  163. data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
  164. data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
  165. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
  166. data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
  167. data/spec/unit/util/network_device_spec.rb +2 -2
  168. data/spec/unit/util/settings/file_setting_spec.rb +4 -0
  169. data/spec/unit/util/settings_spec.rb +11 -0
  170. data/test/lib/puppettest/railstesting.rb +0 -34
  171. metadata +19 -4
@@ -0,0 +1,76 @@
1
+ " Vim indent file
2
+ " Language: Puppet
3
+ " Maintainer: Todd Zullinger <tmz@pobox.com>
4
+ " Last Change: 2009 Aug 19
5
+ " vim: set sw=4 sts=4:
6
+
7
+ if exists("b:did_indent")
8
+ finish
9
+ endif
10
+ let b:did_indent = 1
11
+
12
+ setlocal autoindent smartindent
13
+ setlocal indentexpr=GetPuppetIndent()
14
+ setlocal indentkeys+=0],0)
15
+
16
+ if exists("*GetPuppetIndent")
17
+ finish
18
+ endif
19
+
20
+ " Check if a line is part of an include 'block', e.g.:
21
+ " include foo,
22
+ " bar,
23
+ " baz
24
+ function! s:PartOfInclude(lnum)
25
+ let lnum = a:lnum
26
+ while lnum
27
+ let lnum = lnum - 1
28
+ let line = getline(lnum)
29
+ if line !~ ',$'
30
+ break
31
+ endif
32
+ if line =~ '^\s*include\s\+[^,]\+,$'
33
+ return 1
34
+ endif
35
+ endwhile
36
+ return 0
37
+ endfunction
38
+
39
+ function! s:OpenBrace(lnum)
40
+ call cursor(a:lnum, 1)
41
+ return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW')
42
+ endfunction
43
+
44
+ function! GetPuppetIndent()
45
+ let pnum = prevnonblank(v:lnum - 1)
46
+ if pnum == 0
47
+ return 0
48
+ endif
49
+
50
+ let line = getline(v:lnum)
51
+ let pline = getline(pnum)
52
+ let ind = indent(pnum)
53
+
54
+ if pline =~ '^\s*#'
55
+ return ind
56
+ endif
57
+
58
+ if pline =~ '\({\|\[\|(\|:\)$'
59
+ let ind += &sw
60
+ elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*'
61
+ let ind -= &sw
62
+ elseif pline =~ '^\s*include\s\+.*,$'
63
+ let ind += &sw
64
+ endif
65
+
66
+ if pline !~ ',$' && s:PartOfInclude(pnum)
67
+ let ind -= &sw
68
+ endif
69
+
70
+ " Match } }, }; ] ]: )
71
+ if line =~ '^\s*\(}\(,\|;\)\?$\|]:\?$\|)\)'
72
+ let ind = indent(s:OpenBrace(v:lnum))
73
+ endif
74
+
75
+ return ind
76
+ endfunction
@@ -24,7 +24,7 @@ require 'puppet/util/run_mode'
24
24
  # it's also a place to find top-level commands like 'debug'
25
25
 
26
26
  module Puppet
27
- PUPPETVERSION = '2.7.1'
27
+ PUPPETVERSION = '2.7.3'
28
28
 
29
29
  def Puppet.version
30
30
  PUPPETVERSION
@@ -59,8 +59,7 @@ module Puppet
59
59
 
60
60
  # configuration parameter access and stuff
61
61
  def self.[](param)
62
- case param
63
- when :debug
62
+ if param == :debug
64
63
  return Puppet::Util::Log.level == :debug
65
64
  else
66
65
  return @@settings[param]
@@ -187,10 +187,10 @@ configuration options can also be generated by running puppet agent with
187
187
  should always at least contain MD5, MD2, SHA1 and SHA256.
188
188
 
189
189
  * --detailed-exitcodes:
190
- Provide transaction information via exit codes. If this is enabled, an
191
- exit code of '2' means there were changes, and an exit code of '4'
192
- means that there were failures during the transaction. This option
193
- only makes sense in conjunction with --onetime.
190
+ Provide transaction information via exit codes. If this is enabled, an exit
191
+ code of '2' means there were changes, an exit code of '4' means there were
192
+ failures during the transaction, and an exit code of '6' means there were both
193
+ changes and failures.
194
194
 
195
195
  * --disable:
196
196
  Disable working on the local system. This puts a lock file in place,
@@ -320,7 +320,7 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
320
320
  unless fingerprint = cert.fingerprint(options[:digest])
321
321
  raise ArgumentError, "Could not get fingerprint for digest '#{options[:digest]}'"
322
322
  end
323
- Puppet.notice fingerprint
323
+ puts fingerprint
324
324
  end
325
325
 
326
326
  def onetime
@@ -390,8 +390,8 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
390
390
  end
391
391
 
392
392
  def setup_listen
393
- unless FileTest.exists?(Puppet[:authconfig])
394
- Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}"
393
+ unless FileTest.exists?(Puppet[:rest_authconfig])
394
+ Puppet.err "Will not start without authorization file #{Puppet[:rest_authconfig]}"
395
395
  exit(14)
396
396
  end
397
397
 
@@ -82,9 +82,10 @@ configuration options can also be generated by running puppet with
82
82
  Enable full debugging.
83
83
 
84
84
  * --detailed-exitcodes:
85
- Provide transaction information via exit codes. If this is enabled, an
86
- exit code of '2' means there were changes, and an exit code of '4'
87
- means that there were failures during the transaction.
85
+ Provide transaction information via exit codes. If this is enabled, an exit
86
+ code of '2' means there were changes, an exit code of '4' means there were
87
+ failures during the transaction, and an exit code of '6' means there were both
88
+ changes and failures.
88
89
 
89
90
  * --help:
90
91
  Print this help message
@@ -168,13 +169,18 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
168
169
  end
169
170
 
170
171
  # Collect our facts.
171
- unless facts = Puppet::Node::Facts.indirection.find(Puppet[:certname])
172
- raise "Could not find facts for #{Puppet[:certname]}"
172
+ unless facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
173
+ raise "Could not find facts for #{Puppet[:node_name_value]}"
174
+ end
175
+
176
+ unless Puppet[:node_name_fact].empty?
177
+ Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
178
+ facts.name = Puppet[:node_name_value]
173
179
  end
174
180
 
175
181
  # Find our Node
176
- unless node = Puppet::Node.indirection.find(Puppet[:certname])
177
- raise "Could not find node #{Puppet[:certname]}"
182
+ unless node = Puppet::Node.indirection.find(Puppet[:node_name_value])
183
+ raise "Could not find node #{Puppet[:node_name_value]}"
178
184
  end
179
185
 
180
186
  # Merge in the facts.
@@ -208,7 +214,13 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
208
214
  configurer = Puppet::Configurer.new
209
215
  report = configurer.run(:skip_plugin_download => true, :catalog => catalog)
210
216
 
211
- exit( options[:detailed_exitcodes] ? report.exit_status : 0 )
217
+ if not report
218
+ exit(1)
219
+ elsif options[:detailed_exitcodes] then
220
+ exit(report.exit_status)
221
+ else
222
+ exit(0)
223
+ end
212
224
  rescue => detail
213
225
  puts detail.backtrace if Puppet[:trace]
214
226
  $stderr.puts detail.message
@@ -0,0 +1,5 @@
1
+ require 'puppet/application/face_base'
2
+
3
+ class Puppet::Application::Ca < Puppet::Application::FaceBase
4
+ run_mode :master
5
+ end
@@ -218,7 +218,8 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
218
218
  if sub = self.command_line.args.shift then
219
219
  self.subcommand = sub
220
220
  else
221
- help
221
+ puts help
222
+ exit
222
223
  end
223
224
  end
224
225
  result
@@ -2,11 +2,6 @@ require 'puppet/application/indirection_base'
2
2
 
3
3
  class Puppet::Application::Certificate < Puppet::Application::IndirectionBase
4
4
  def setup
5
- unless options[:ca_location]
6
- raise ArgumentError, "You must have a CA location specified;\n" +
7
- "use --ca-location to specify the location (remote, local, only)"
8
- end
9
-
10
5
  location = Puppet::SSL::Host.ca_location
11
6
  if location == :local && !Puppet::SSL::CertificateAuthority.ca?
12
7
  self.class.run_mode("master")
@@ -113,10 +113,10 @@ parameter, so you can specify '--server <servername>' as an argument.
113
113
  Enable full debugging.
114
114
 
115
115
  * --detailed-exitcodes:
116
- Provide transaction information via exit codes. If this is enabled, an
117
- exit code of '2' means there were changes, and an exit code of '4' means
118
- that there were failures during the transaction. This option only makes
119
- sense in conjunction with --onetime.
116
+ Provide transaction information via exit codes. If this is enabled, an exit
117
+ code of '2' means there were changes, an exit code of '4' means there were
118
+ failures during the transaction, and an exit code of '6' means there were both
119
+ changes and failures.
120
120
 
121
121
  * --help:
122
122
  Print this help message
@@ -87,29 +87,40 @@ puppet doc will output a single manifest's documentation on stdout.
87
87
  OPTIONS
88
88
  -------
89
89
  * --all:
90
- Output the docs for all of the reference types. In 'rdoc'
91
- modes, this also outputs documentation for all resources
90
+ Output the docs for all of the reference types. In 'rdoc' mode, this also
91
+ outputs documentation for all resources.
92
92
 
93
93
  * --help:
94
94
  Print this help message
95
95
 
96
96
  * --outputdir:
97
- Specifies the directory where to output the rdoc
98
- documentation in 'rdoc' mode.
97
+ Used only in 'rdoc' mode. The directory to which the rdoc output should
98
+ be written.
99
99
 
100
100
  * --mode:
101
- Determine the output mode. Valid modes are 'text', 'pdf' and
102
- 'rdoc'. The 'pdf' mode creates PDF formatted files in the
103
- /tmp directory. The default mode is 'text'. In 'rdoc' mode
104
- you must provide 'manifests-path'
101
+ Determine the output mode. Valid modes are 'text', 'pdf' and 'rdoc'. The 'pdf'
102
+ mode creates PDF formatted files in the /tmp directory. The default mode is
103
+ 'text'. In 'rdoc' mode you must provide 'manifests-path'
105
104
 
106
105
  * --reference:
107
- Build a particular reference. Get a list of references by
108
- running 'puppet doc --list'.
106
+ Build a particular reference. Get a list of references by running
107
+ 'puppet doc --list'.
109
108
 
110
109
  * --charset:
111
- Used only in 'rdoc' mode. It sets the charset used in the
112
- html files produced.
110
+ Used only in 'rdoc' mode. It sets the charset used in the html files produced.
111
+
112
+ * --manifestdir:
113
+ Used only in 'rdoc' mode. The directory to scan for stand-alone manifests.
114
+ If not supplied, puppet doc will use the manifestdir from puppet.conf.
115
+
116
+ * --modulepath:
117
+ Used only in 'rdoc' mode. The directory or directories to scan for modules.
118
+ If not supplied, puppet doc will use the modulepath from puppet.conf.
119
+
120
+ * --environment:
121
+ Used only in 'rdoc' mode. The configuration environment from which
122
+ to read the modulepath and manifestdir settings, when reading said settings
123
+ from puppet.conf. Due to a known bug, this option is not currently effective.
113
124
 
114
125
 
115
126
  EXAMPLE
@@ -100,7 +100,8 @@ class Puppet::Application::FaceBase < Puppet::Application
100
100
  # action object it represents; if this is an invalid action name that
101
101
  # will be nil, and handled later.
102
102
  action_name = item.to_sym
103
- @action = @face.get_action(action_name)
103
+ @action = Puppet::Face.find_action(@face.name, action_name)
104
+ @face = @action.face if @action
104
105
  end
105
106
  end
106
107
 
@@ -1,6 +1,4 @@
1
- require 'puppet'
2
1
  require 'puppet/application'
3
- require 'puppet/file_bucket/dipper'
4
2
 
5
3
  class Puppet::Application::Inspect < Puppet::Application
6
4
 
@@ -98,6 +96,11 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
98
96
  Puppet::Resource::Catalog.indirection.terminus_class = :yaml
99
97
  end
100
98
 
99
+ def preinit
100
+ require 'puppet'
101
+ require 'puppet/file_bucket/dipper'
102
+ end
103
+
101
104
  def run_command
102
105
  benchmark(:notice, "Finished inspection") do
103
106
  retrieval_starttime = Time.now
@@ -5,8 +5,6 @@ require 'puppet/network/http_pool'
5
5
  require 'puppet/util'
6
6
 
7
7
  class Puppet::Configurer
8
- class CommandHookError < RuntimeError; end
9
-
10
8
  require 'puppet/configurer/fact_handler'
11
9
  require 'puppet/configurer/plugin_handler'
12
10
 
@@ -79,21 +77,11 @@ class Puppet::Configurer
79
77
  download_plugins unless options[:skip_plugin_download]
80
78
 
81
79
  download_fact_plugins unless options[:skip_plugin_download]
82
-
83
- execute_prerun_command
84
80
  end
85
81
 
86
82
  # Get the remote catalog, yo. Returns nil if no catalog can be found.
87
- def retrieve_catalog
88
- if Puppet::Resource::Catalog.indirection.terminus_class == :rest
89
- # This is a bit complicated. We need the serialized and escaped facts,
90
- # and we need to know which format they're encoded in. Thus, we
91
- # get a hash with both of these pieces of information.
92
- fact_options = facts_for_uploading
93
- else
94
- fact_options = {}
95
- end
96
-
83
+ def retrieve_catalog(fact_options)
84
+ fact_options ||= {}
97
85
  # First try it with no cache, then with the cache.
98
86
  unless (Puppet[:use_cached_catalog] and result = retrieve_catalog_from_cache(fact_options)) or result = retrieve_new_catalog(fact_options)
99
87
  if ! Puppet[:usecacheonfailure]
@@ -117,60 +105,73 @@ class Puppet::Configurer
117
105
  catalog
118
106
  end
119
107
 
108
+ # Retrieve (optionally) and apply a catalog. If a catalog is passed in
109
+ # the options, then apply that one, otherwise retrieve it.
110
+ def retrieve_and_apply_catalog(options, fact_options)
111
+ unless catalog = (options.delete(:catalog) || retrieve_catalog(fact_options))
112
+ Puppet.err "Could not retrieve catalog; skipping run"
113
+ return
114
+ end
115
+
116
+ report = options[:report]
117
+ report.configuration_version = catalog.version
118
+
119
+ benchmark(:notice, "Finished catalog run") do
120
+ catalog.apply(options)
121
+ end
122
+
123
+ report.finalize_report
124
+ report
125
+ end
126
+
120
127
  # The code that actually runs the catalog.
121
128
  # This just passes any options on to the catalog,
122
129
  # which accepts :tags and :ignoreschedules.
123
130
  def run(options = {})
124
- begin
125
- prepare(options)
126
- rescue SystemExit,NoMemoryError
127
- raise
128
- rescue Exception => detail
129
- puts detail.backtrace if Puppet[:trace]
130
- Puppet.err "Failed to prepare catalog: #{detail}"
131
- end
132
-
133
131
  options[:report] ||= Puppet::Transaction::Report.new("apply")
134
132
  report = options[:report]
135
- Puppet::Util::Log.newdestination(report)
136
133
 
137
- if catalog = options[:catalog]
138
- options.delete(:catalog)
139
- elsif ! catalog = retrieve_catalog
140
- Puppet.err "Could not retrieve catalog; skipping run"
141
- return
142
- end
134
+ Puppet::Util::Log.newdestination(report)
135
+ begin
136
+ prepare(options)
143
137
 
144
- report.configuration_version = catalog.version
138
+ if Puppet::Resource::Catalog.indirection.terminus_class == :rest
139
+ # This is a bit complicated. We need the serialized and escaped facts,
140
+ # and we need to know which format they're encoded in. Thus, we
141
+ # get a hash with both of these pieces of information.
142
+ fact_options = facts_for_uploading
143
+ end
145
144
 
146
- transaction = nil
145
+ # set report host name now that we have the fact
146
+ report.host = Puppet[:node_name_value]
147
147
 
148
- begin
149
- benchmark(:notice, "Finished catalog run") do
150
- transaction = catalog.apply(options)
148
+ begin
149
+ execute_prerun_command or return nil
150
+ retrieve_and_apply_catalog(options, fact_options)
151
+ rescue SystemExit,NoMemoryError
152
+ raise
153
+ rescue => detail
154
+ puts detail.backtrace if Puppet[:trace]
155
+ Puppet.err "Failed to apply catalog: #{detail}"
156
+ return nil
157
+ ensure
158
+ execute_postrun_command or return nil
151
159
  end
152
- report
153
- rescue => detail
154
- puts detail.backtrace if Puppet[:trace]
155
- Puppet.err "Failed to apply catalog: #{detail}"
156
- return
160
+ ensure
161
+ # Make sure we forget the retained module_directories of any autoload
162
+ # we might have used.
163
+ Thread.current[:env_module_directories] = nil
164
+
165
+ # Now close all of our existing http connections, since there's no
166
+ # reason to leave them lying open.
167
+ Puppet::Network::HttpPool.clear_http_instances
157
168
  end
158
169
  ensure
159
- # Make sure we forget the retained module_directories of any autoload
160
- # we might have used.
161
- Thread.current[:env_module_directories] = nil
162
-
163
- # Now close all of our existing http connections, since there's no
164
- # reason to leave them lying open.
165
- Puppet::Network::HttpPool.clear_http_instances
166
- execute_postrun_command
167
-
168
170
  Puppet::Util::Log.close(report)
169
- send_report(report, transaction)
171
+ send_report(report)
170
172
  end
171
173
 
172
- def send_report(report, trans)
173
- report.finalize_report if trans
174
+ def send_report(report)
174
175
  puts report.summary if Puppet[:summarize]
175
176
  save_last_run_summary(report)
176
177
  Puppet::Transaction::Report.indirection.save(report) if Puppet[:report]
@@ -208,19 +209,22 @@ class Puppet::Configurer
208
209
  end
209
210
 
210
211
  def execute_from_setting(setting)
211
- return if (command = Puppet[setting]) == ""
212
+ return true if (command = Puppet[setting]) == ""
212
213
 
213
214
  begin
214
215
  Puppet::Util.execute([command])
216
+ true
215
217
  rescue => detail
216
- raise CommandHookError, "Could not run command from #{setting}: #{detail}"
218
+ puts detail.backtrace if Puppet[:trace]
219
+ Puppet.err "Could not run command from #{setting}: #{detail}"
220
+ false
217
221
  end
218
222
  end
219
223
 
220
224
  def retrieve_catalog_from_cache(fact_options)
221
225
  result = nil
222
226
  @duration = thinmark do
223
- result = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], fact_options.merge(:ignore_terminus => true))
227
+ result = Puppet::Resource::Catalog.indirection.find(Puppet[:node_name_value], fact_options.merge(:ignore_terminus => true))
224
228
  end
225
229
  Puppet.notice "Using cached catalog"
226
230
  result
@@ -233,7 +237,7 @@ class Puppet::Configurer
233
237
  def retrieve_new_catalog(fact_options)
234
238
  result = nil
235
239
  @duration = thinmark do
236
- result = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], fact_options.merge(:ignore_cache => true))
240
+ result = Puppet::Resource::Catalog.indirection.find(Puppet[:node_name_value], fact_options.merge(:ignore_cache => true))
237
241
  end
238
242
  result
239
243
  rescue SystemExit,NoMemoryError