Class: Ridley::BootstrapContext::Windows

Inherits:
Base
  • Object
show all
Defined in:
lib/ridley-connectors/bootstrap_context/windows.rb

Overview

Represents a binding that will be evaluated as an ERB template. When bootstrapping nodes, an instance of this class represents the customizable and necessary configurations needed by the Host in order to install and connect to Chef. By default, this class will be used when WinRM is the best way to connect to the node.

Windows Specific code written by Seth Chisamore (<[email protected]>) in knife-windows github.com/opscode/knife-windows/blob/3b8886ddcfb928ca0958cd05b22f8c3d78bee86e/lib/chef/knife/bootstrap/windows-chef-client-msi.erb github.com/opscode/knife-windows/blob/78d38bbed358ac20107fc2b5b427f4b5e52e5cb2/lib/chef/knife/core/windows_bootstrap_context.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #bootstrap_proxy, #chef_version, #environment, #hints, #node_name, #run_list, #server_url, #template_file, #validator_client, #validator_path

Instance Method Summary collapse

Methods inherited from Base

#bootstrap_command, #initialize, #template, #templates_path, validate_options

Constructor Details

This class inherits a constructor from Ridley::BootstrapContext::Base

Instance Method Details

#boot_commandString



13
14
15
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 13

def boot_command
  template.evaluate(self)
end

#bootstrap_directoryString



45
46
47
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 45

def bootstrap_directory
  "C:\\chef"
end

#chef_configString



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 18

def chef_config
  body = "  log_level        :info\n  log_location     STDOUT\n  chef_server_url  \"\#{server_url}\"\n  validation_client_name \"\#{validator_client}\"\n  CONFIG\n\n  if node_name.present?\n    body << %Q{node_name \"\#{node_name}\"\\n}\n  else\n    body << \"# Using default node name (fqdn)\\n\"\n  end\n\n  if bootstrap_proxy.present?\n    body << %Q{http_proxy        \"\#{bootstrap_proxy}\"\\n}\n    body << %Q{https_proxy       \"\#{bootstrap_proxy}\"\\n}\n  end\n\n  if encrypted_data_bag_secret.present?\n    body << %Q{encrypted_data_bag_secret '\#{bootstrap_directory}\\\\encrypted_data_bag_secret'\\n}\n  end\n\n  escape_and_echo(body)\nend\n"

#chef_runString



55
56
57
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 55

def chef_run
  "chef-client -j #{bootstrap_directory}\\first-boot.json -E #{environment}"
end

#default_templateString



60
61
62
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 60

def default_template
  templates_path.join('windows_omnibus.erb').to_s
end

#encrypted_data_bag_secretString



65
66
67
68
69
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 65

def encrypted_data_bag_secret
  return unless @encrypted_data_bag_secret

  escape_and_echo(@encrypted_data_bag_secret)
end

#env_pathString



101
102
103
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 101

def env_path
  "C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin"
end

#escape_and_echo(file_contents) ⇒ Object

escape WIN BATCH special chars and prefixes each line with an echo



113
114
115
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 113

def escape_and_echo(file_contents)
  file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
end

#first_bootString



96
97
98
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 96

def first_boot
  escape_and_echo(super)
end

#install_chefString



91
92
93
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 91

def install_chef
  'msiexec /qb /i "%LOCAL_DESTINATION_MSI_PATH%"'
end

#local_download_pathString



106
107
108
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 106

def local_download_path
  "%TEMP%\\chef-client-#{chef_version}.msi"
end

#validation_keyString



50
51
52
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 50

def validation_key
  escape_and_echo(super)
end

#windows_wget_powershellString

Implements a Powershell script that attempts a simple ‘wget’ to download the Chef msi



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ridley-connectors/bootstrap_context/windows.rb', line 75

def windows_wget_powershell
  win_wget_ps = "  param(\n   [String] $remoteUrl,\n   [String] $localPath\n  )\n\n  $webClient = new-object System.Net.WebClient;\n\n  $webClient.DownloadFile($remoteUrl, $localPath);\n  WGET_PS\n\n  escape_and_echo(win_wget_ps)\nend\n"