Class: VagrantWindows::Provisioners::ChefCommandBuilder
- Inherits:
-
Object
- Object
- VagrantWindows::Provisioners::ChefCommandBuilder
show all
- Includes:
- Helper
- Defined in:
- lib/vagrant-windows/provisioners/chef_command_builder.rb
Overview
Builds scripts and ultimately the command to execute Chef solo or Chef client on Windows guests using a scheduled task.
Instance Method Summary
collapse
Methods included from Helper
#wait_if_rebooting, #win_friendly_path, #win_friendly_share_id
Constructor Details
#initialize(windows_machine, chef_config, client_type) ⇒ ChefCommandBuilder
Returns a new instance of ChefCommandBuilder.
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 14
def initialize(windows_machine, chef_config, client_type)
@windows_machine = windows_machine
@config = chef_config
if client_type != :solo && client_type != :client
raise 'Invalid client_type, expected solo or client'
end
@client_type = client_type
end
|
Instance Method Details
#chef_binary_path ⇒ Object
Returns the path to the Chef binary, taking into account the ‘binary_path` configuration option.
93
94
95
96
97
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 93
def chef_binary_path()
binary = "chef-#{@client_type}"
return binary if !@config.binary_path
return win_friendly_path(File.join(@config.binary_path, binary))
end
|
#chef_task_ps1_path ⇒ Object
87
88
89
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 87
def chef_task_ps1_path()
provisioning_path('cheftask.ps1')
end
|
#create_chef_arguments ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 76
def create_chef_arguments()
command_args = @config.arguments ? @config.arguments : ''
chef_path = provisioning_path("#{@client_type}.rb")
chef_dna_path = provisioning_path('dna.json')
chef_arguments = "-c #{chef_path}"
chef_arguments << " -j #{chef_dna_path}"
chef_arguments << " #{command_args}"
chef_arguments.strip
end
|
#create_chef_options ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 59
def create_chef_options
command_env = @config.binary_env ? "#{@config.binary_env} " : ''
return {
:user => @windows_machine.winrm_config.username,
:pass => @windows_machine.winrm_config.password,
:chef_arguments => create_chef_arguments(),
:chef_task_xml => provisioning_path('cheftask.xml'),
:chef_task_running => provisioning_path('cheftask.running'),
:chef_task_exitcode => provisioning_path('cheftask.exitcode'),
:chef_task_ps1 => chef_task_ps1_path(),
:chef_task_run_ps1 => provisioning_path('cheftaskrun.ps1'),
:chef_stdout_log => provisioning_path("chef-#{@client_type}.log"),
:chef_stderr_log => provisioning_path("chef-#{@client_type}.err.log"),
:chef_binary_path => win_friendly_path("#{command_env}#{chef_binary_path}")
}
end
|
#prepare_for_chef_run ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 25
def prepare_for_chef_run()
options = create_chef_options()
render_file_and_upload('cheftaskrun.ps1', options[:chef_task_run_ps1],
:options => options)
render_file_and_upload('cheftask.xml', options[:chef_task_xml],
:options => options)
render_file_and_upload('cheftask.ps1', options[:chef_task_ps1],
:options => options)
end
|
#provisioning_path(file_name) ⇒ Object
99
100
101
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 99
def provisioning_path(file_name)
win_friendly_path("#{@config.provisioning_path}/#{file_name}")
end
|
#render_file_and_upload(script_name, dest_file, options) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 52
def render_file_and_upload(script_name, dest_file, options)
script_local = Tempfile.new(script_name)
IO.write(script_local, VagrantWindows.load_script_template(script_name, options))
@windows_machine.winrmshell.upload(script_local, dest_file)
end
|
#run_chef_command ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/vagrant-windows/provisioners/chef_command_builder.rb', line 41
def run_chef_command()
return " $old = Get-ExecutionPolicy;\n Set-ExecutionPolicy Unrestricted -force;\n \#{chef_task_ps1_path};\n Set-ExecutionPolicy $old -force\n EOH\nend\n"
|