chef-apply 0.1.2 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,341 @@
1
+ # Error definitions, usage Text.e.ERR999
2
+ # General format:
3
+ # First Line: brief description of the error
4
+ # Second line: blank
5
+ # Third+ : detailed description, max 76 characters per line
6
+ errors:
7
+ rendering_defaults: {header: true, footer: true, stack: true, log: true}
8
+ # Catch-all for the worst case
9
+ UNKNOWN: An unknown error has occurred.
10
+
11
+ # Installer action errors
12
+ CHEFINS002:
13
+ The target does not have chef-client installed.
14
+
15
+ This command is powered by the Chef client. In order to make use of it
16
+ on this node, the Chef client must be installed first.
17
+
18
+ Re-running this command without the '--no-install' flag will
19
+ automatically perform the installation.
20
+
21
+ CHEFINS003: |
22
+ The target's installed version of Chef Client is too old.
23
+
24
+ Version %1 is installed, but this command requires a
25
+ minimum version of %2 (Chef 13) or %3 (Chef 14).
26
+
27
+ CHEFINS004: |
28
+ The target's installed version of Chef Client is too old.
29
+
30
+ Version %1 is installed, but this command requires a
31
+ minimum version of %2.
32
+
33
+ # Local errors trying to create policy to send to target
34
+ CHEFPOLICY001: |
35
+ Could not create local Policyfile bundle.
36
+
37
+ The following error was reported:
38
+
39
+ %1
40
+
41
+ # Remote execution and file operation errors are prefixed CHEFRMT
42
+ CHEFRMT001: |
43
+ The command '%1' exited with return code '%2' on '%3'.
44
+
45
+ The following error was reported:
46
+
47
+ %4
48
+
49
+ # Remote chef client run failure start here.
50
+ CHEFCCR001: |
51
+ Could not determine reason for converge failure.
52
+
53
+ STDOUT (may be blank)
54
+
55
+ %1
56
+
57
+ STDERR (may be blank)
58
+
59
+ %2
60
+
61
+ An error occurred while converging the remote host.
62
+ I was unable to retrieve the log file which would allow
63
+ me to provide more information. Above is the output
64
+ that occurred while trying to retrieve the remote log file.
65
+
66
+ CHEFCCR002: |
67
+ The converge of the remote host failed for the
68
+ following reason:
69
+
70
+ %1
71
+
72
+ CHEFCCR003: |
73
+ The action '%1' is not valid.
74
+
75
+ Valid actions are:
76
+
77
+ %2
78
+
79
+ For more information, please consult the documentation
80
+ for this resource:
81
+
82
+ https://docs.chef.io/resource_reference.html
83
+
84
+ CHEFCCR004: |
85
+ A property value you provided is not valid:
86
+
87
+ %1
88
+
89
+ Please consult the documentation for properties
90
+ supported by your resource and their valid values:
91
+
92
+ https://docs.chef.io/resource_reference.html
93
+
94
+ CHEFCCR005: |
95
+ '%1' is not a valid Chef resource.
96
+
97
+ Please consult the documentation for a list of valid resources:
98
+
99
+ https://docs.chef.io/resource_reference.html
100
+
101
+ CHEFCCR006: |
102
+ '%1' is not a property of '%2'.
103
+
104
+ Please consult the documentation for %2 for a list of
105
+ valid properties:
106
+
107
+ https://docs.chef.io/resource_reference.html
108
+
109
+ CHEFCCR099: |
110
+ The converge of the remote host failed.
111
+
112
+ Please examine the log file for a detailed cause of failure.
113
+
114
+ # Train-related errors (connectivy, auth failure, etc)
115
+ # are prefixed CHEFTRN. Non-specific descendants of Train::Error
116
+ # will resolve to CHEFTRN001, and we can add additional
117
+ # more specific text as we need it.
118
+ CHEFTRN001: |
119
+ An error has occurred on the %1 connection to %2:
120
+
121
+ %2.
122
+
123
+ CHEFTRN002: |
124
+ An remote error has occurred:
125
+
126
+ %1.
127
+
128
+ CHEFTRN003: |
129
+ Password required for sudo.
130
+
131
+ This target requires a password to perform sudo operations. Please provide a
132
+ password using the --sudo-password option. For example if the sudo password is
133
+ in the environment variable $CHEF_RUN_SUDO_PASSWORD, you could use:
134
+
135
+ --sudo-password $CHEF_RUN_SUDO_PASSWORD
136
+
137
+ CHEFTRN004: |
138
+ Incorrect sudo password provided.
139
+
140
+ Please ensure that the password you provided with "--sudo-password" is correct.
141
+
142
+ CHEFTRN005: |
143
+ sudo command '%1' not found.
144
+
145
+ Please verify that the --sudo-command '%1' is valid
146
+ and installed on this node.
147
+
148
+ CHEFTRN006: |
149
+ sudo requires tty on this system
150
+
151
+ In order to continue, sudo must be configured to no longer require tty.
152
+ You can do this by modifying /etc/sudoers:
153
+
154
+ For all users:
155
+ Defaults !requiretty
156
+
157
+ Per-user:
158
+ Defaults:username !requiretty
159
+
160
+ CHEFTRN007: |
161
+ No authentication methods available.
162
+
163
+ Try...
164
+ - Provide a password with "--password PASSWORD"
165
+ - Provide a key with "-identity-file PATH/TO/FILE"
166
+ - Enable ssh-agent and add keys
167
+ - Add a host entry to your ssh configuration
168
+
169
+ Additional instructions can be found in the troubleshooting documentation:
170
+
171
+ https://www.chef.sh/docs/chef-workstation/troubleshooting/#error-code-cheftrn007
172
+
173
+ CHEFTRN999: |
174
+ Connection failed: %1
175
+
176
+ The following error occured while attempting to connect and authenticate to the target.
177
+
178
+ %1
179
+
180
+ # CLI argument validation errors
181
+ CHEFVAL002: |
182
+ You must supply <TARGET[S]> and either <RESOURCE> and <RESOURCE_NAME> or <RECIPE>
183
+
184
+ CHEFVAL003: |
185
+ Property '%1' did not match the 'key=value' syntax required
186
+
187
+ CHEFVAL004: |
188
+ Please provide a recipe in the form 'path/to/recipe/file.rb',
189
+ 'path/to/cookbook', 'cookbook_name' or 'cookbook_name::recipe_name'.
190
+
191
+ You provided '%1'.
192
+
193
+ CHEFVAL005: |
194
+ The cookbook provided could not be loaded. Ensure it contains a valid
195
+ 'metadata.rb'.
196
+
197
+ Cookbook path is '%1'.
198
+
199
+ CHEFVAL006: |
200
+ Cookbook '%1' could not be found in any of the following directories
201
+
202
+ %2
203
+
204
+ CHEFVAL007: |
205
+ There is no default recipe in cookbook '%2'. Please provide the name of the recipe to run, for example:
206
+ %2::some_recipe
207
+
208
+ Cookbook path is '%1'.
209
+
210
+ CHEFVAL008: |
211
+ There is no recipe named '%2' in the cookbook '%4', which I found at '%1'.
212
+
213
+ Please include the name of the recipe you wish to converge on the remote target.
214
+
215
+ These are the available recipes in '%4':
216
+ %3
217
+
218
+ CHEFVAL009: |
219
+ File extension '%1' is unsupported. Currently recipes must be specified with a `.rb` extension.
220
+
221
+ CHEFVAL010: |
222
+ The flag '%1' does not exist.
223
+
224
+ Available flags are:
225
+ %2
226
+
227
+ CHEFVAL011: |
228
+ The protocol '%1' is not supported.
229
+
230
+ Currently supported remote access protocols are:
231
+
232
+ %2
233
+
234
+ # General errors/unknown errors are handled with CHEFINT
235
+ CHEFINT001: |
236
+ An unexpected error has occurred:
237
+
238
+ %1
239
+
240
+ # Internal API errors - give them some formatting
241
+ CHEFAPI001: |
242
+ API error: provide either :recipe_spec or :resouce_name, :resource_type,
243
+ and :resource_properties
244
+
245
+ You provided: %1
246
+
247
+
248
+ # Maps to: NameError
249
+ CHEFNET001: |
250
+ A network error occurred:
251
+
252
+ %1
253
+
254
+ Please verify the host name or address is correct and that the host is
255
+ reachable before trying again.
256
+
257
+ # Remote chef client run failure start here.
258
+ CHEFUPL003: |
259
+ Uploading config to target failed.
260
+
261
+ CHEFUPL004: |
262
+ Uploading handler to target failed.
263
+
264
+ CHEFUPL005: |
265
+ Uploading policy bundle to target failed.
266
+
267
+ # Maps to: SSL::SSLError with message text indicating verification failure
268
+ CHEFNET002: |
269
+ SSL host verification failed.
270
+
271
+ I could not verify the identity of the remote host.
272
+
273
+ If you are certain that you are connecting to the correct host,
274
+ you can specify the '--no-ssl-verify' option for this command, or
275
+ make it the default by setting the following in your configuration:
276
+
277
+ [connection.winrm]
278
+ ssl_verify=false
279
+
280
+ # Errors specifying target ranges
281
+ CHEFRANGE001: |
282
+ The target '%1' contains an invalid range.
283
+
284
+ The range '%2' mixes alphabetic and numeric values.
285
+ A range must be one or the other.
286
+
287
+ CHEFRANGE002:
288
+ The target '%1' contains too many ranges.
289
+
290
+ A single target name can contain up two ranges.
291
+
292
+ CHEFRANGE003: !!pl
293
+ 1:
294
+ The target provided resolves to too many hosts.
295
+
296
+ At this time there is a limit of %2 hosts in a single operation.
297
+ n:
298
+ The targets provided resolve to too many hosts.
299
+
300
+ At this time there is a limit of %2 hosts in a single operation.
301
+
302
+ # Errors related to multi-target execution
303
+ CHEFMULTI001: |
304
+ One or more actions has failed.
305
+
306
+ A complete list of failures and possible resolutions can
307
+ be found in the file below:
308
+
309
+ %1
310
+
311
+ # Errors relating to target state:
312
+ CHEFTARG001: |
313
+ '%1' is not a supported target operating system at this time.
314
+
315
+ We plan to support a range of target operating systems,
316
+ but during this targeted beta we are constraining our efforts
317
+ to Windows and Linux.
318
+
319
+
320
+ footer:
321
+ both: |
322
+ If you are not able to resolve this issue, please contact Chef support
323
+ at beta@chef.io and include the log file and stack trace from the
324
+ locations below:
325
+
326
+ %1
327
+ %2
328
+
329
+ log_only: |
330
+ If you are not able to resolve this issue, please contact Chef support
331
+ at beta@chef.io and include the log file from the location below:
332
+ %1
333
+
334
+ stack_only: |
335
+ If you are not able to resolve this issue, please contact Chef support
336
+ at beta@chef.io and include the stack trace from the location below:
337
+ %1
338
+
339
+ neither: |
340
+ If you are not able to resolve this issue, please contact Chef support
341
+ at beta@chef.io
@@ -84,6 +84,10 @@ module ChefApply
84
84
  # Chef will try 'downloading' the policy from the internet unless we pass it a valid, local file
85
85
  # in the working directory. By pointing it at a local file it will just copy it instead of trying
86
86
  # to download it.
87
+ #
88
+ # Chef 13 on Linux requires full path specifiers for --config and --recipe-url while on Chef 13 and 14 on
89
+ # Windows must use relative specifiers to prevent URI from causing an error
90
+ # (https://github.com/chef/chef/pull/7223/files).
87
91
  def run_chef(working_dir, config, policy)
88
92
  case family
89
93
  when :windows
@@ -96,7 +100,7 @@ module ChefApply
96
100
  else
97
101
  # cd is shell a builtin, so much call bash. This also means all commands are executed
98
102
  # with sudo (as long as we are hardcoding our sudo use)
99
- "bash -c 'cd #{working_dir}; chef-client -z --config #{config} --recipe-url #{policy}'"
103
+ "bash -c 'cd #{working_dir}; chef-client -z --config #{File.join(working_dir, config)} --recipe-url #{File.join(working_dir, policy)}'"
100
104
  end
101
105
  end
102
106
 
@@ -0,0 +1,59 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2017 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "chef_apply/action/base"
19
+ require "chef_apply/error"
20
+ module ChefApply::Action
21
+ class GenerateLocalPolicy < Base
22
+ attr_reader :archive_file_location
23
+ def initialize(config)
24
+ super(config)
25
+ @cookbook = config.delete :cookbook
26
+ end
27
+
28
+ def perform_action
29
+ notify(:generating)
30
+ installer.run
31
+ notify(:exporting)
32
+ exporter.run
33
+ @archive_file_location = exporter.archive_file_location
34
+ notify(:success)
35
+ rescue ChefDK::PolicyfileInstallError => e
36
+ raise PolicyfileInstallError.new(e)
37
+ end
38
+
39
+ def exporter
40
+ require "chef-dk/policyfile_services/export_repo"
41
+ @exporter ||=
42
+ ChefDK::PolicyfileServices::ExportRepo.new(policyfile: @cookbook.policyfile_lock_path,
43
+ root_dir: @cookbook.path,
44
+ export_dir: @cookbook.export_path,
45
+ archive: true, force: true)
46
+ end
47
+
48
+ def installer
49
+ require "chef-dk/policyfile_services/install"
50
+ require "chef-dk/ui"
51
+ @installer ||=
52
+ ChefDK::PolicyfileServices::Install.new(ui: ChefDK::UI.null(), root_dir: @cookbook.path)
53
+ end
54
+
55
+ end
56
+ class PolicyfileInstallError < ChefApply::Error
57
+ def initialize(cause_err); super("CHEFPOLICY001", cause_err.message); end
58
+ end
59
+ end
@@ -0,0 +1,86 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2018 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "chef_apply/action/base"
19
+ require "chef_apply/temp_cookbook"
20
+ require "chef_apply/error"
21
+
22
+ module ChefApply::Action
23
+ class GenerateTempCookbook < Base
24
+ attr_reader :generated_cookbook
25
+
26
+ def self.from_options(opts)
27
+ if opts.has_key?(:recipe_spec)
28
+ GenerateCookbookFromRecipe.new(opts)
29
+ elsif opts.has_key?(:resource_name) &&
30
+ opts.has_key?(:resource_type) &&
31
+ opts.has_key?(:resource_properties)
32
+ GenerateCookbookFromResource.new(opts)
33
+ else
34
+ raise MissingOptions.new(opts)
35
+ end
36
+ end
37
+
38
+ def initialize(options)
39
+ super(options)
40
+ @generated_cookbook ||= ChefApply::TempCookbook.new
41
+ end
42
+
43
+ def perform_action
44
+ notify(:generating)
45
+ generate
46
+ notify(:success)
47
+ end
48
+
49
+ def generate
50
+ raise NotImplemented
51
+ end
52
+ end
53
+
54
+ class GenerateCookbookFromRecipe < GenerateTempCookbook
55
+ def generate
56
+ recipe_specifier = config.delete :recipe_spec
57
+ repo_paths = config.delete :cookbook_repo_paths
58
+ ChefApply::Log.debug("Beginning to look for recipe specified as #{recipe_specifier}")
59
+ if File.file?(recipe_specifier)
60
+ ChefApply::Log.debug("#{recipe_specifier} is a valid path to a recipe")
61
+ recipe_path = recipe_specifier
62
+ else
63
+ require "chef_apply/recipe_lookup"
64
+ rl = ChefApply::RecipeLookup.new(repo_paths)
65
+ cookbook_path_or_name, optional_recipe_name = rl.split(recipe_specifier)
66
+ cookbook = rl.load_cookbook(cookbook_path_or_name)
67
+ recipe_path = rl.find_recipe(cookbook, optional_recipe_name)
68
+ end
69
+ generated_cookbook.from_existing_recipe(recipe_path)
70
+ end
71
+ end
72
+
73
+ class GenerateCookbookFromResource < GenerateTempCookbook
74
+ def generate
75
+ type = config.delete :resource_type
76
+ name = config.delete :resource_name
77
+ props = config.delete :resource_properties
78
+ ChefApply::Log.debug("Generating cookbook for ad-hoc resource #{type}[#{name}]")
79
+ generated_cookbook.from_resource(type, name, props)
80
+ end
81
+ end
82
+
83
+ class MissingOptions < ChefApply::APIError
84
+ def initialize(*args); super("CHEFAPI001", *args); end
85
+ end
86
+ end