Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Unknown
-
Resolution: Fixed
-
Affects Version/s: 0.10.8
-
Fix Version/s: 10.14.0
-
Component/s: Chef Client
-
Labels:None
Description
Chef::Resource::Execute only allows String objects to be passed to the command attribute, though the underlying machinery supports Arrays, too. Since the :kind_of checks don't apply to the name attribute, Arrays can be used in some cases already, and work well:
This is shef, the Chef shell. Chef Version: 0.10.8 http://www.opscode.com/chef http://wiki.opscode.com/display/chef/Home run `help' for help, `exit' or ^D to quit. Ohai2u will@dev-user-api001! chef > recipe chef:recipe > execute %w{ls /etc/motd} => <execute[ls/etc/motd] @retries: 0 @updated: false @allowed_actions: [:nothing, :run] @name: ["ls", "/etc/motd"] @enclosing_provider: nil @creates: nil @resource_name: :execute @delayed_notifications: [] @before: nil @ignore_failure: false @user: nil @timeout: nil @cwd: nil @command: ["ls", "/etc/motd"] @action: "run" @recipe_name: nil @immediate_notifications: [] @noop: nil @umask: nil @supports: {} @group: nil @environment: nil @backup: 5 @source_line: "(irb#1):1:in `irb_binding'" @provider: nil @cookbook_name: nil @retry_delay: 2 @updated_by_last_action: false @returns: 0 @path: nil @params: {}> chef:recipe > run_chef [Mon, 07 May 2012 18:01:44 +0000] DEBUG: Processing execute[ls/etc/motd] on dev-user-api001 [Mon, 07 May 2012 18:01:44 +0000] INFO: Processing execute[ls/etc/motd] action run ((irb#1) line 1) [Mon, 07 May 2012 18:01:44 +0000] INFO: execute[ls/etc/motd] sh(ls/etc/motd) /etc/motd [Mon, 07 May 2012 18:01:44 +0000] INFO: execute[ls/etc/motd] ran successfully => true
Attempts to do the same using the command attribute fail:
chef > recipe chef:recipe > execute "test" do chef:recipe > command %w{ls /etc/motd} chef:recipe ?> end Chef::Exceptions::ValidationFailed: Option command must be a kind of String! You passed ["ls", "/etc/motd"]. from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:140:in `_pv_kind_of' from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:69:in `send' from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:69:in `validate' from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:66:in `each' from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:66:in `validate' from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:56:in `each' from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:56:in `validate' from /usr/lib/ruby/vendor_ruby/chef/mixin/params_validate.rb:88:in `set_or_return' from /usr/lib/ruby/vendor_ruby/chef/resource/execute.rb:53:in `command' from (irb#1):2 from /usr/lib/ruby/vendor_ruby/chef/mixin/recipe_definition_dsl_core.rb:69:in `instance_eval' from /usr/lib/ruby/vendor_ruby/chef/mixin/recipe_definition_dsl_core.rb:69:in `method_missing' from (irb#1):1
Passing an Array allows the caller to execute a command directly and avoid invoking a shell, which in turn can reduce bugs due to expansion of special characters by the shell.
Activity
Bryan McLellan [Opscode]
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
Bryan McLellan [Opscode]
made changes -
| Triage Status | [Triaged] |
Bryan McLellan [Opscode]
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
| Fix Version/s | 10.14.0 [ 10901 ] |
Bryan McLellan [Opscode]
made changes -
| Component/s | Chef Client [ 10000 ] | |
| Component/s | Resources [ 10004 ] |
Bryan McLellan [Opscode]
made changes -
| Workflow | jira [ 15742 ] | New OSS [ 20438 ] |
Bryan McLellan [Opscode]
made changes -
| Workflow | New OSS [ 20438 ] | OSS: Product Management [ 28357 ] |
| Transition | Time In Source Status | Execution Times | Last Executer | Last Execution Date | |||||
|---|---|---|---|---|---|---|---|---|---|
|
1d 38m | 1 | Bryan McLellan [Opscode] | 08/May/12 8:04 PM | |||||
|
42d 2h 5m | 1 | Bryan McLellan [Opscode] | 19/Jun/12 10:09 PM |
See Chef PR#287: https://github.com/opscode/chef/pull/287