Chef: windows_batch: how to pass the Windows Administrator password from Chef workstation to Chef node

1.6k views Asked by At

I am starting up Windows servers (2008r2 Datacenter Edition) on Amazon EC2 using Chef. In this scenario, I run a script.

railsdev@deb7> knife ec2 server create -VV -I ami-xxxxxxx --flavor=m1.medium --groups=windows_target --region=us-east-1 --ssh-key=deployme --identity-file=/home/railsdev/Development/me-chef-repo/.chef/deployme.pem --bootstrap-protocol winrm --template-file=/home/railsdev/Development/me-chef-repo/windows-chef-client-msi.erb --user-data=/home/railsdev/Development/me-chef-repo/enable-winrm.ps1 --run-list 'role[me-win]' --node-name=jgodse-xx-65

This script successfully starts an EC2 node and runs my recipes.

One of the Chef recipes I want to run uses a windows_batch resource as follows:

windows_batch "start_me" do
   cwd "C:/me"
   code 'C:\Ruby193\ruby.exe C:\me\start_me.rb'    
end

'start_me.rb' starts a Windows service which runs as user "Local System Account". However I need to run the service as Administrator, and I therefore need to pass the script the Administrator password.

I envision the new windows_batch to look like this:

windows_batch "start_me" do
   cwd "C:/me"
   code 'C:\Ruby193\ruby.exe C:\me\start_me.rb pass=' + passwd    
end

I know that the windows password exists on the Chef workstation side in the knife variable called Chef::Config[:knife][:winrm_password]. However, when I dumped the Chef::Config with this resource:

windows_batch "Chef::Config[:knife]" do
  code <<-EOHH
  @ECHO OFF

  ECHO Chef::Config[:knife] = #{Chef::Config[:knife].inspect} >> %SystemDrive%\plchef_config_knife_jgodse.txt
  EOHH
end

I got a big fat "{}" in plchef_config_knife_jgodse.txt on the Chef node. i.e. The Chef::Config[:knife] data didn't make it from the Chef workstation to the Chef node.

How can I get the Windows Administrator password, which is stored in Chef::Config[:knife][:winrm_password] on the server, to be available to the windows_batch(){} provider which runs on the Chef node inside one of my Chef recipes?

1

There are 1 answers

0
Julian Dunn On

You can't do exactly what you're asking. The configuration settings of the administrator tool, knife, don't get sent over to the server in any way.