ridley-connectors 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/bootstrappers/unix_omnibus.erb +91 -0
- data/bootstrappers/windows_omnibus.erb +113 -0
- data/lib/ridley-connectors.rb +10 -0
- data/lib/ridley-connectors/bootstrap_context.rb +100 -0
- data/lib/ridley-connectors/bootstrap_context/unix.rb +66 -0
- data/lib/ridley-connectors/bootstrap_context/windows.rb +118 -0
- data/lib/ridley-connectors/command_context.rb +76 -0
- data/lib/ridley-connectors/command_context/unix_uninstall.rb +42 -0
- data/lib/ridley-connectors/command_context/windows_uninstall.rb +35 -0
- data/lib/ridley-connectors/errors.rb +29 -0
- data/lib/ridley-connectors/host_commander.rb +26 -9
- data/lib/ridley-connectors/host_connector/ssh.rb +3 -0
- data/lib/ridley-connectors/host_connector/winrm.rb +21 -25
- data/lib/ridley-connectors/version.rb +1 -1
- data/ridley-connectors.gemspec +1 -0
- data/scripts/unix_uninstall_omnibus.erb +31 -0
- data/scripts/windows_uninstall_omnibus.erb +10 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/ridley-connectors/bootstrap_context/unix_spec.rb +101 -0
- data/spec/unit/ridley-connectors/bootstrap_context/windows_spec.rb +116 -0
- data/spec/unit/ridley-connectors/bootstrap_context_spec.rb +52 -0
- data/spec/unit/ridley-connectors/client_spec.rb +1 -1
- data/spec/unit/ridley-connectors/command_context_spec.rb +56 -0
- data/spec/unit/ridley-connectors/host_commander_spec.rb +23 -0
- data/spec/unit/ridley-connectors/host_connector/winrm_spec.rb +31 -23
- metadata +36 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cc8a35d12c2f0a211941000d82e951c738d1f0b
|
4
|
+
data.tar.gz: 8793248c34607319be63abfbab2f0b5831f6ef2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c08b024e392d443a050676e690e591342973c6fb105b4961f904cf2b1937eff4f2516751d6a2ad9d292ae58bbb2afc1456c675dc8d736e8d7b75aeae9813ac
|
7
|
+
data.tar.gz: 74a3bba5e041055a7b2cfc02c38aff93132feeed3cbe4144d29f19f6c43c1897e9b9576f1a629339379aa01550d10d86673c5c3137a1a48d438dacde9f3a3919
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v.2.0.1
|
2
|
+
|
3
|
+
* [#18](https://github.com/RiotGames/ridley-connectors/pull/18) Move more connector-specific code out of ridley and into ridley-connectors
|
4
|
+
* [#19](https://github.com/RiotGames/ridley-connectors/pull/19) Add some extra logging to retrying connections to choose an appropriate connector
|
5
|
+
* [#20](https://github.com/RiotGames/ridley-connectors/pull/20) Handle HostCommander, WinRM, and SSH actor crashes better
|
6
|
+
|
7
|
+
## v.2.0.0
|
8
|
+
|
9
|
+
* [#17](https://github.com/RiotGames/ridley-connectors/pull/17) Bump ridley dependency to 3.0.0
|
10
|
+
|
1
11
|
## v.1.7.1
|
2
12
|
|
3
13
|
* [#16](https://github.com/RiotGames/ridley-connectors/pull/16) JRuby throws different exceptions when it can't connect to a node
|
@@ -0,0 +1,91 @@
|
|
1
|
+
bash -c '
|
2
|
+
<%= "export http_proxy=\"#{bootstrap_proxy}\"" if bootstrap_proxy -%>
|
3
|
+
|
4
|
+
exists() {
|
5
|
+
if command -v $1 &>/dev/null
|
6
|
+
then
|
7
|
+
return 0
|
8
|
+
else
|
9
|
+
return 1
|
10
|
+
fi
|
11
|
+
}
|
12
|
+
|
13
|
+
install_chef() {
|
14
|
+
install_sh="http://opscode.com/chef/install.sh"
|
15
|
+
proxy_string="<%= "--proxy=on " if bootstrap_proxy %>"
|
16
|
+
|
17
|
+
if [[ $requested_chef_version != "" ]]; then
|
18
|
+
version_string="-v $requested_chef_version"
|
19
|
+
else
|
20
|
+
version_string=""
|
21
|
+
fi
|
22
|
+
|
23
|
+
if exists wget; then
|
24
|
+
bash <(wget ${proxy_string} ${install_sh} -O -) ${version_string}
|
25
|
+
else
|
26
|
+
if exists curl; then
|
27
|
+
bash <(curl -L ${proxy_string} ${install_sh}) ${version_string}
|
28
|
+
fi
|
29
|
+
fi
|
30
|
+
}
|
31
|
+
|
32
|
+
requested_chef_version="<%= chef_version %>"
|
33
|
+
installed_chef_version="$(which chef-client &>/dev/null && chef-client -v | cut -f 2 -d " ")"
|
34
|
+
|
35
|
+
if [[ ! $installed_chef_version ]]; then
|
36
|
+
install_chef
|
37
|
+
elif [[ ($requested_chef_version != "") && ($installed_chef_version != $requested_chef_version) ]]; then
|
38
|
+
install_chef
|
39
|
+
fi
|
40
|
+
|
41
|
+
mkdir -p /etc/chef
|
42
|
+
|
43
|
+
(
|
44
|
+
cat <<'EOP'
|
45
|
+
<%= validation_key %>
|
46
|
+
EOP
|
47
|
+
) > /tmp/validation.pem
|
48
|
+
awk NF /tmp/validation.pem > /etc/chef/validation.pem
|
49
|
+
rm /tmp/validation.pem
|
50
|
+
chmod 0600 /etc/chef/validation.pem
|
51
|
+
|
52
|
+
<% if encrypted_data_bag_secret -%>
|
53
|
+
(
|
54
|
+
cat <<'EOP'
|
55
|
+
<%= encrypted_data_bag_secret %>
|
56
|
+
EOP
|
57
|
+
) > /tmp/encrypted_data_bag_secret
|
58
|
+
awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret
|
59
|
+
rm /tmp/encrypted_data_bag_secret
|
60
|
+
chmod 0600 /etc/chef/encrypted_data_bag_secret
|
61
|
+
<% end -%>
|
62
|
+
|
63
|
+
<%# Generate Ohai Hints -%>
|
64
|
+
<% unless hints.empty? -%>
|
65
|
+
mkdir -p /etc/chef/ohai/hints
|
66
|
+
|
67
|
+
<% hints.each do |name, hash| -%>
|
68
|
+
(
|
69
|
+
cat <<'EOP'
|
70
|
+
<%= hash.to_json %>
|
71
|
+
EOP
|
72
|
+
) > /etc/chef/ohai/hints/<%= name %>.json
|
73
|
+
<% end -%>
|
74
|
+
<% end -%>
|
75
|
+
|
76
|
+
(
|
77
|
+
cat <<'EOP'
|
78
|
+
<%= chef_config %>
|
79
|
+
EOP
|
80
|
+
) > /etc/chef/client.rb
|
81
|
+
|
82
|
+
<%# Remove client pem if it already exists -%>
|
83
|
+
rm /etc/chef/client.pem
|
84
|
+
|
85
|
+
(
|
86
|
+
cat <<'EOP'
|
87
|
+
<%= first_boot %>
|
88
|
+
EOP
|
89
|
+
) > /etc/chef/first-boot.json
|
90
|
+
|
91
|
+
<%= chef_run %>'
|
@@ -0,0 +1,113 @@
|
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
rem Author:: Kyle Allan (<kallan@riotgames.com>)
|
4
|
+
rem Original Author:
|
5
|
+
rem
|
6
|
+
rem Author:: Seth Chisamore (<schisam@oopscode.com>)
|
7
|
+
rem Copyright:: Copyright (c) 2011 Opscode, Inc.
|
8
|
+
rem License:: Apache License, Version 2.0
|
9
|
+
rem
|
10
|
+
rem Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
rem you may not use this file except in compliance with the License.
|
12
|
+
rem You may obtain a copy of the License at
|
13
|
+
rem
|
14
|
+
rem http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
rem
|
16
|
+
rem Unless required by applicable law or agreed to in writing, software
|
17
|
+
rem distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
rem See the License for the specific language governing permissions and
|
20
|
+
rem limitations under the License.
|
21
|
+
rem
|
22
|
+
|
23
|
+
setlocal
|
24
|
+
|
25
|
+
<%= "SETX HTTP_PROXY \"#{bootstrap_proxy}\"" if bootstrap_proxy %>
|
26
|
+
mkdir <%= bootstrap_directory %>
|
27
|
+
|
28
|
+
> <%= bootstrap_directory %>\wget.ps1 (
|
29
|
+
<%= windows_wget_powershell %>
|
30
|
+
)
|
31
|
+
|
32
|
+
rem Determine the version and the architecture
|
33
|
+
|
34
|
+
FOR /F "tokens=1-8 delims=.[] " %%A IN ('ver') DO (
|
35
|
+
set WinMajor=%%D
|
36
|
+
set WinMinor=%%E
|
37
|
+
set WinBuild=%%F
|
38
|
+
)
|
39
|
+
|
40
|
+
goto Version%WinMajor%.%WinMinor%
|
41
|
+
|
42
|
+
rem If this is an unknown version of windows set the default
|
43
|
+
set MACHINE_OS=2008r2
|
44
|
+
goto architecture
|
45
|
+
|
46
|
+
:Version6.0
|
47
|
+
set MACHINE_OS=2008
|
48
|
+
goto architecture
|
49
|
+
|
50
|
+
:Version5.2
|
51
|
+
set MACHINE_OS=2003r2
|
52
|
+
goto architecture
|
53
|
+
|
54
|
+
:Version6.1
|
55
|
+
set MACHINE_OS=2008r2
|
56
|
+
goto architecture
|
57
|
+
|
58
|
+
:Version6.2
|
59
|
+
set MACHINE_OS=2012
|
60
|
+
goto architecture
|
61
|
+
|
62
|
+
:architecture
|
63
|
+
|
64
|
+
goto Architecture%PROCESSOR_ARCHITECTURE%
|
65
|
+
|
66
|
+
rem If this is an unknown architecture set the default
|
67
|
+
set MACHINE_ARCH=i686
|
68
|
+
goto install
|
69
|
+
|
70
|
+
:Architecturex86
|
71
|
+
set MACHINE_ARCH=i686
|
72
|
+
goto install
|
73
|
+
|
74
|
+
:Architectureamd64
|
75
|
+
set MACHINE_ARCH=x86_64
|
76
|
+
goto install
|
77
|
+
|
78
|
+
:install
|
79
|
+
rem Install Chef using chef-client MSI installer
|
80
|
+
|
81
|
+
set "VERSION_STRING=<%= chef_version %>"
|
82
|
+
set "REMOTE_SOURCE_MSI_URL=https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%&v=%VERSION_STRING%"
|
83
|
+
set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
|
84
|
+
set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
|
85
|
+
|
86
|
+
powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive "& '<%= bootstrap_directory %>\wget.ps1' '%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%' '%LOCAL_DESTINATION_MSI_PATH%'"
|
87
|
+
|
88
|
+
<%= install_chef %>
|
89
|
+
|
90
|
+
endlocal
|
91
|
+
|
92
|
+
> <%= bootstrap_directory %>\validation.pem (
|
93
|
+
<%= validation_key %>
|
94
|
+
)
|
95
|
+
|
96
|
+
<% if encrypted_data_bag_secret -%>
|
97
|
+
> <%= bootstrap_directory %>\encrypted_data_bag_secret (
|
98
|
+
<%= encrypted_data_bag_secret %>
|
99
|
+
)
|
100
|
+
<% end -%>
|
101
|
+
|
102
|
+
> <%= bootstrap_directory %>\client.rb (
|
103
|
+
<%= chef_config %>
|
104
|
+
)
|
105
|
+
|
106
|
+
> <%= bootstrap_directory %>\first-boot.json (
|
107
|
+
<%= first_boot %>
|
108
|
+
)
|
109
|
+
|
110
|
+
SET "PATH=%PATH%;<%= env_path %>"
|
111
|
+
SETX PATH "%PATH;<%= env_path %>"
|
112
|
+
|
113
|
+
<%= chef_run %>
|
data/lib/ridley-connectors.rb
CHANGED
@@ -3,9 +3,19 @@ require 'celluloid/io'
|
|
3
3
|
require 'ridley'
|
4
4
|
|
5
5
|
module Ridley
|
6
|
+
class << self
|
7
|
+
# @return [Pathname]
|
8
|
+
def scripts
|
9
|
+
root.join('scripts')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
require_relative 'ridley-connectors/client'
|
14
|
+
require_relative 'ridley-connectors/bootstrap_context'
|
15
|
+
require_relative 'ridley-connectors/command_context'
|
7
16
|
require_relative 'ridley-connectors/host_commander'
|
8
17
|
require_relative 'ridley-connectors/host_connector'
|
9
18
|
require_relative 'ridley-connectors/chef_objects/node_object'
|
10
19
|
require_relative 'ridley-connectors/resources/node_resource'
|
20
|
+
require_relative 'ridley-connectors/errors'
|
11
21
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
|
3
|
+
module Ridley
|
4
|
+
module BootstrapContext
|
5
|
+
class Base
|
6
|
+
class << self
|
7
|
+
def validate_options(options = {})
|
8
|
+
if options[:server_url].nil?
|
9
|
+
raise Errors::ArgumentError, "A server_url is required for bootstrapping"
|
10
|
+
end
|
11
|
+
|
12
|
+
if options[:validator_path].nil?
|
13
|
+
raise Errors::ArgumentError, "A path to a validator is required for bootstrapping"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :template_file
|
19
|
+
attr_reader :bootstrap_proxy
|
20
|
+
attr_reader :chef_version
|
21
|
+
attr_reader :validator_path
|
22
|
+
attr_reader :encrypted_data_bag_secret
|
23
|
+
attr_reader :server_url
|
24
|
+
attr_reader :validator_client
|
25
|
+
attr_reader :node_name
|
26
|
+
attr_reader :attributes
|
27
|
+
attr_reader :run_list
|
28
|
+
attr_reader :environment
|
29
|
+
attr_reader :hints
|
30
|
+
|
31
|
+
def initialize(options = {})
|
32
|
+
options = options.reverse_merge(
|
33
|
+
validator_client: "chef-validator",
|
34
|
+
attributes: Hash.new,
|
35
|
+
run_list: Array.new,
|
36
|
+
environment: "_default",
|
37
|
+
sudo: true,
|
38
|
+
hints: Hash.new,
|
39
|
+
chef_version: "latest"
|
40
|
+
)
|
41
|
+
options[:template] ||= default_template
|
42
|
+
self.class.validate_options(options)
|
43
|
+
|
44
|
+
@template_file = options[:template]
|
45
|
+
@bootstrap_proxy = options[:bootstrap_proxy]
|
46
|
+
@chef_version = options[:chef_version]
|
47
|
+
@sudo = options[:sudo]
|
48
|
+
@validator_path = options[:validator_path]
|
49
|
+
@encrypted_data_bag_secret = options[:encrypted_data_bag_secret]
|
50
|
+
@hints = options[:hints]
|
51
|
+
@server_url = options[:server_url]
|
52
|
+
@validator_client = options[:validator_client]
|
53
|
+
@node_name = options[:node_name]
|
54
|
+
@attributes = options[:attributes]
|
55
|
+
@run_list = options[:run_list]
|
56
|
+
@environment = options[:environment]
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [String]
|
60
|
+
def bootstrap_command
|
61
|
+
raise RuntimeError, "abstract function: must be implemented on includer"
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [String]
|
65
|
+
def default_template
|
66
|
+
raise RuntimeError, "abstract function: must be implemented on includer"
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Pathname]
|
70
|
+
def templates_path
|
71
|
+
Ridley.root.join('bootstrappers')
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [String]
|
75
|
+
def first_boot
|
76
|
+
JSON.fast_generate(attributes.merge(run_list: run_list))
|
77
|
+
end
|
78
|
+
|
79
|
+
# The validation key to create a new client for the node
|
80
|
+
#
|
81
|
+
# @raise [Ridley::Errors::ValidatorNotFound]
|
82
|
+
#
|
83
|
+
# @return [String]
|
84
|
+
def validation_key
|
85
|
+
IO.read(File.expand_path(validator_path)).chomp
|
86
|
+
rescue Errno::ENOENT
|
87
|
+
raise Errors::ValidatorNotFound, "Error bootstrapping: Validator not found at '#{validator_path}'"
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [Erubis::Eruby]
|
91
|
+
def template
|
92
|
+
Erubis::Eruby.new(IO.read(template_file).chomp)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Dir["#{File.dirname(__FILE__)}/bootstrap_context/*.rb"].sort.each do |path|
|
99
|
+
require_relative "bootstrap_context/#{File.basename(path, '.rb')}"
|
100
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Ridley
|
2
|
+
module BootstrapContext
|
3
|
+
# Represents a binding that will be evaluated as an ERB template. When bootstrapping
|
4
|
+
# nodes, an instance of this class represents the customizable and necessary configurations
|
5
|
+
# needed by the Host in order to install and connect to Chef. By default, this class will be used
|
6
|
+
# when SSH is the best way to connect to the node.
|
7
|
+
class Unix < BootstrapContext::Base
|
8
|
+
attr_reader :sudo
|
9
|
+
|
10
|
+
# @option options [Boolean] :sudo (true)
|
11
|
+
# bootstrap with sudo (default: true)
|
12
|
+
def initialize(options = {})
|
13
|
+
options = options.reverse_merge(sudo: true)
|
14
|
+
@sudo = options[:sudo]
|
15
|
+
super(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
def boot_command
|
20
|
+
template.evaluate(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [String]
|
24
|
+
def chef_config
|
25
|
+
body = <<-CONFIG
|
26
|
+
log_level :info
|
27
|
+
log_location STDOUT
|
28
|
+
chef_server_url "#{server_url}"
|
29
|
+
validation_client_name "#{validator_client}"
|
30
|
+
CONFIG
|
31
|
+
|
32
|
+
if node_name.present?
|
33
|
+
body << %Q{node_name "#{node_name}"\n}
|
34
|
+
else
|
35
|
+
body << "# Using default node name (fqdn)\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
if bootstrap_proxy.present?
|
39
|
+
body << %Q{http_proxy "#{bootstrap_proxy}"\n}
|
40
|
+
body << %Q{https_proxy "#{bootstrap_proxy}"\n}
|
41
|
+
end
|
42
|
+
|
43
|
+
if encrypted_data_bag_secret.present?
|
44
|
+
body << %Q{encrypted_data_bag_secret "#{bootstrap_directory}/encrypted_data_bag_secret"\n}
|
45
|
+
end
|
46
|
+
|
47
|
+
body
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [String]
|
51
|
+
def bootstrap_directory
|
52
|
+
"/etc/chef"
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String]
|
56
|
+
def chef_run
|
57
|
+
"chef-client -j #{bootstrap_directory}/first-boot.json -E #{environment}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String]
|
61
|
+
def default_template
|
62
|
+
templates_path.join('unix_omnibus.erb').to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Ridley
|
2
|
+
module BootstrapContext
|
3
|
+
# Represents a binding that will be evaluated as an ERB template. When bootstrapping
|
4
|
+
# nodes, an instance of this class represents the customizable and necessary configurations
|
5
|
+
# needed by the Host in order to install and connect to Chef. By default, this class will be used
|
6
|
+
# when WinRM is the best way to connect to the node.
|
7
|
+
#
|
8
|
+
# Windows Specific code written by Seth Chisamore (<schisamo@opscode.com>) in knife-windows
|
9
|
+
# https://github.com/opscode/knife-windows/blob/3b8886ddcfb928ca0958cd05b22f8c3d78bee86e/lib/chef/knife/bootstrap/windows-chef-client-msi.erb
|
10
|
+
# https://github.com/opscode/knife-windows/blob/78d38bbed358ac20107fc2b5b427f4b5e52e5cb2/lib/chef/knife/core/windows_bootstrap_context.rb
|
11
|
+
class Windows < BootstrapContext::Base
|
12
|
+
# @return [String]
|
13
|
+
def boot_command
|
14
|
+
template.evaluate(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String]
|
18
|
+
def chef_config
|
19
|
+
body = <<-CONFIG
|
20
|
+
log_level :info
|
21
|
+
log_location STDOUT
|
22
|
+
chef_server_url "#{server_url}"
|
23
|
+
validation_client_name "#{validator_client}"
|
24
|
+
CONFIG
|
25
|
+
|
26
|
+
if node_name.present?
|
27
|
+
body << %Q{node_name "#{node_name}"\n}
|
28
|
+
else
|
29
|
+
body << "# Using default node name (fqdn)\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
if bootstrap_proxy.present?
|
33
|
+
body << %Q{http_proxy "#{bootstrap_proxy}"\n}
|
34
|
+
body << %Q{https_proxy "#{bootstrap_proxy}"\n}
|
35
|
+
end
|
36
|
+
|
37
|
+
if encrypted_data_bag_secret.present?
|
38
|
+
body << %Q{encrypted_data_bag_secret '#{bootstrap_directory}\\encrypted_data_bag_secret'\n}
|
39
|
+
end
|
40
|
+
|
41
|
+
escape_and_echo(body)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [String]
|
45
|
+
def bootstrap_directory
|
46
|
+
"C:\\chef"
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String]
|
50
|
+
def validation_key
|
51
|
+
escape_and_echo(super)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String]
|
55
|
+
def chef_run
|
56
|
+
"chef-client -j #{bootstrap_directory}\\first-boot.json -E #{environment}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [String]
|
60
|
+
def default_template
|
61
|
+
templates_path.join('windows_omnibus.erb').to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [String]
|
65
|
+
def encrypted_data_bag_secret
|
66
|
+
return unless @encrypted_data_bag_secret
|
67
|
+
|
68
|
+
escape_and_echo(@encrypted_data_bag_secret)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Implements a Powershell script that attempts a simple
|
72
|
+
# 'wget' to download the Chef msi
|
73
|
+
#
|
74
|
+
# @return [String]
|
75
|
+
def windows_wget_powershell
|
76
|
+
win_wget_ps = <<-WGET_PS
|
77
|
+
param(
|
78
|
+
[String] $remoteUrl,
|
79
|
+
[String] $localPath
|
80
|
+
)
|
81
|
+
|
82
|
+
$webClient = new-object System.Net.WebClient;
|
83
|
+
|
84
|
+
$webClient.DownloadFile($remoteUrl, $localPath);
|
85
|
+
WGET_PS
|
86
|
+
|
87
|
+
escape_and_echo(win_wget_ps)
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [String]
|
91
|
+
def install_chef
|
92
|
+
'msiexec /qb /i "%LOCAL_DESTINATION_MSI_PATH%"'
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [String]
|
96
|
+
def first_boot
|
97
|
+
escape_and_echo(super)
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [String]
|
101
|
+
def env_path
|
102
|
+
"C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin"
|
103
|
+
end
|
104
|
+
|
105
|
+
# @return [String]
|
106
|
+
def local_download_path
|
107
|
+
"%TEMP%\\chef-client-#{chef_version}.msi"
|
108
|
+
end
|
109
|
+
|
110
|
+
# escape WIN BATCH special chars
|
111
|
+
# and prefixes each line with an
|
112
|
+
# echo
|
113
|
+
def escape_and_echo(file_contents)
|
114
|
+
file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|