Class: Kitchen::Provisioner::ChefZeroScheduledTask
- Inherits:
-
ChefZero
- Object
- ChefZero
- Kitchen::Provisioner::ChefZeroScheduledTask
- Defined in:
- lib/kitchen/provisioner/chef_zero_scheduled_task.rb
Overview
Chef Zero provisioner to run in scheduled task on Windows
Instance Method Summary collapse
- #create_sandbox ⇒ Object
- #init_command ⇒ Object
-
#prepare_command ⇒ Object
assuming a version of Chef with local mode.
- #run_command ⇒ Object
Instance Method Details
#create_sandbox ⇒ Object
32 33 34 35 36 |
# File 'lib/kitchen/provisioner/chef_zero_scheduled_task.rb', line 32 def create_sandbox super return unless windows_os? prepare_client_zero_script end |
#init_command ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/kitchen/provisioner/chef_zero_scheduled_task.rb', line 38 def init_command resolve_username_and_password wrap_shell_code( " $cmd_path = \"\#{remote_path_join(config[:root_path], \"chef-client-script.ps1\")}\"\n $cmd_line = $executioncontext.invokecommand.expandstring(\"powershell -executionpolicy unrestricted -File $cmd_path\")\n schtasks /create /tn \"chef-tk\" /ru \#{@task_username} /rp \#{@task_password} /sc daily /st 00:00 /f /tr \"$cmd_line\"\n EOH\n )\nend\n" |
#prepare_command ⇒ Object
assuming a version of Chef with local mode.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kitchen/provisioner/chef_zero_scheduled_task.rb', line 49 def prepare_command return unless windows_os? info('Creating a script to run chef client.') cmd = " $pre_cmd = \"`$env:temp = `\"$env:temp`\"\"\n $cmd_path = \"\#{remote_path_join(config[:root_path], \"chef-client-script.ps1\")}\"\n $cmd_to_eval = gc $cmd_path | out-string\n $cmd = $executioncontext.invokecommand.expandstring($cmd_to_eval)\n $pre_cmd, $cmd | out-file $cmd_path\n EOH\n wrap_shell_code(cmd)\nend\n" |
#run_command ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kitchen/provisioner/chef_zero_scheduled_task.rb', line 62 def run_command wrap_shell_code( " if (test-path 'c:/chef/tk.log') {\n remove-item c:/chef/tk.log -force\n }\n schtasks /run /tn \"chef-tk\"\n $host.ui.WriteLine('Running scheduled task chef-tk.')\n do {\n $host.ui.WriteLine(' The task is still running.')\n start-sleep -seconds 5\n $state = schtasks /query /tn chef-tk /fo csv /v | convertfrom-csv\n } while ($state.status -like 'Running')\n $host.ui.WriteLine('')\n get-content c:/chef/tk.log -readcount 0\n EOH\n )\nend\n" |