summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Cheslock <pcheslock@sonian.com>2012-11-20 13:42:25 -0500
committerPete Cheslock <pcheslock@sonian.com>2012-11-20 13:43:39 -0500
commitb2726d616be3f8c72bd22f1eeae794133dcd2575 (patch)
tree90b8e8542e75bb8b1de130d1f221e3625044af9b
parent36616f741efb2def3f240dbb6917732900754638 (diff)
downloadmixlib-shellout-b2726d616be3f8c72bd22f1eeae794133dcd2575.tar.gz
COOK-1932 - Introduce :change action to task LWRP
-rw-r--r--README.md10
-rw-r--r--providers/task.rb17
2 files changed, 27 insertions, 0 deletions
diff --git a/README.md b/README.md
index 025761d..a19c7cd 100644
--- a/README.md
+++ b/README.md
@@ -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 1185fc7..7222633 100644
--- a/providers/task.rb
+++ b/providers/task.rb
@@ -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.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!"
+ 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}\""