Skip to content

Instantly share code, notes, and snippets.

@cpuguy83
Last active December 30, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpuguy83/7771365 to your computer and use it in GitHub Desktop.
Save cpuguy83/7771365 to your computer and use it in GitHub Desktop.
Custom Chef bootstrap for Windows
#!/usr/bin/env ruby
require 'winrm'
IP=ARGV[0]
USER=ARGV[1]
endpoint = "http://#{IP}:5985/wsman"
winrm = WinRM::WinRMWebService.new endpoint, :plaintext, user: USER, pass: 'secret', basic_auth_only: true
winrm.set_timeout 1800
installer_file = "c:\\Users\\#{USER}\\Downloads\\chef_client.msi"
installer_cmd = "msiexec /qn /i #{installer_file} ADDLOCAL=\"ChefServiceFeature,ChefClientFeature\""
puts 'Installating Chef'
install_output = winrm.cmd installer_cmd
sleep 300
puts 'Configuring Chef'
winrm.cmd %Q(mv c:\\Users\\#{USER}\\Downloads\\client.rb c:\\chef\\client.rb)
winrm.cmd %Q(mv c:\\Users\\#{USER}\\Downloads\\chef-validator.pem c:\\chef\\validation.pem)
winrm.cmd 'net start chef-client || net start chef-client'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment