diff options
author | Joshua Timberman <joshua@opscode.com> | 2012-12-10 10:28:59 -0800 |
---|---|---|
committer | Joshua Timberman <joshua@opscode.com> | 2012-12-10 10:28:59 -0800 |
commit | 7f649cf6806967bc3d31d82d58bce2947a4f3fe6 (patch) | |
tree | 31a73faeee5f8ecc3680a2b0e117fcaf7ed8d8f5 | |
parent | 6f6b24736cfa2e24b85dc92b1cbecbb0cff939a3 (diff) | |
parent | 833b5a1c2c8bd171c2170789997201a4615ad2fa (diff) | |
download | mixlib-shellout-7f649cf6806967bc3d31d82d58bce2947a4f3fe6.tar.gz |
Merge pull request #13 from pcheslock/task-lwrp
COOK-1932 - Introduce :change action to task LWRP
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | providers/task.rb | 19 | ||||
-rw-r--r-- | resources/task.rb | 3 |
3 files changed, 29 insertions, 3 deletions
@@ -359,6 +359,7 @@ Server 2008 due to API usage. - :create: creates a task - :delete: deletes a task - :run: runs a task +- :change: changes the un/pw or command of a task ### Attribute Parameters @@ -384,6 +385,15 @@ Server 2008 due to API usage. frequency_modifier 15 end + # Update Chef Client task with new password and log location + windows_task "Chef client" do + user "Administrator" + password "N3wPassW0Rd" + cwd "C:\chef\bin" + command "chef-client -L C:\chef\logs\" + action :change + end + # Delete a taks named "old task" windows_task "old task" do action :delete diff --git a/providers/task.rb b/providers/task.rb index 5b10c34..9a2be2e 100644 --- a/providers/task.rb +++ b/providers/task.rb @@ -31,7 +31,7 @@ action :create do if @new_resource.user && @new_resource.password cmd += "/RU \"#{@new_resource.user}\" /RP \"#{@new_resource.password}\" " elsif (@new_resource.user and !@new_resource.password) || (@new_resource.password and !@new_resource.user) - Chef::Log.warn "#{@new_resource.name}: Can't specify user or password without both!" + Chef::Log.fatal "#{@new_resource.name}: Can't specify user or password without both!" end cmd += "/RL HIGHEST " if @new_resource.run_level == :highest shell_out!(cmd, {:returns => [0]}) @@ -55,6 +55,23 @@ action :run do end end +action :change do + if @current_resource.exists + cmd = "schtasks /Change /TN \"#{@current_resource.name}\" " + cmd += "/TR \"#{@new_resource.command}\" " if @new_resource.command + if @new_resource.user && @new_resource.password + cmd += "/RU \"#{@new_resource.user}\" /RP \"#{@new_resource.password}\" " + elsif (@new_resource.user and !@new_resource.password) || (@new_resource.password and !@new_resource.user) + Chef::Log.fatal "#{@new_resource.name}: Can't specify user or password without both!" + end + shell_out!(cmd, {:returns => [0]}) + @new_resource.updated_by_last_action true + Chef::Log.info "Change #{@new_resource} task ran" + else + Chef::Log.debug "#{@new_resource} task doesn't exists - nothing to do" + end +end + action :delete do if @current_resource.exists cmd = "schtasks /Delete /TN \"#{@current_resource.name}\"" diff --git a/resources/task.rb b/resources/task.rb index d5cf985..e0c4a2d 100644 --- a/resources/task.rb +++ b/resources/task.rb @@ -23,7 +23,7 @@ actions :create, :delete, :run attribute :name, :kind_of => String, :name_attribute => true -attribute :command, :kind_of => String, :required => true +attribute :command, :kind_of => String attribute :cwd, :kind_of => String attribute :user, :kind_of => String, :default => nil attribute :password, :kind_of => String, :default => nil @@ -43,5 +43,4 @@ attr_accessor :exists, :status def initialize(name, run_context=nil) super @action = :create - @command = name end |