Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unattend.xml for winrm setup script #44

Merged
merged 4 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions lib/kitchen/driver/azurerm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ def template_for_transport_name
if instance.platform.name.index('nano').nil?
info 'Adding WinRM configuration to provisioning profile.'
encoded_command = Base64.strict_encode64(enable_winrm_powershell_script)
command = command_to_execute
template['resources'].select { |h| h['type'] == 'Microsoft.Compute/virtualMachines' }.each do |resource|
resource['properties']['osProfile']['customData'] = encoded_command
resource['properties']['osProfile']['windowsConfiguration'] = windows_unattend_content
end
template['resources'] << JSON.parse(custom_script_extension_template(command))
end
end

Expand Down Expand Up @@ -333,13 +332,10 @@ def enable_winrm_powershell_script
New-NetFirewallRule -DisplayName "Windows Remote Management (HTTPS-In)" -Name "Windows Remote Management (HTTPS-In)" -Profile Any -LocalPort 5986 -Protocol TCP
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
New-NetFirewallRule -DisplayName "Windows Remote Management (HTTP-In)" -Name "Windows Remote Management (HTTP-In)" -Profile Any -LocalPort 5985 -Protocol TCP
logoff
PS1
end

def command_to_execute
'copy /y c:\\\\azuredata\\\\customdata.bin c:\\\\azuredata\\\\customdata.ps1 && powershell.exe -ExecutionPolicy Unrestricted -Command \\"start-process powershell.exe -verb runas -argumentlist c:\\\\azuredata\\\\customdata.ps1\\"'
end

def custom_linux_configuration(public_key)
<<-EOH
{
Expand All @@ -356,26 +352,23 @@ def custom_linux_configuration(public_key)
EOH
end

def custom_script_extension_template(command)
<<-EOH
def windows_unattend_content
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('vmName'),'/','enableWinRM')]",
"apiVersion": "2015-05-01-preview",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/',variables('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.4",
"settings": {
"commandToExecute": "#{command}"
}
additionalUnattendContent: [
{
passName: 'oobeSystem',
componentName: 'Microsoft-Windows-Shell-Setup',
settingName: 'FirstLogonCommands',
content: '<FirstLogonCommands><SynchronousCommand><CommandLine>cmd /c "copy C:\\AzureData\\CustomData.bin C:\\Config.ps1"</CommandLine><Description>copy</Description><Order>1</Order></SynchronousCommand><SynchronousCommand><CommandLine>%windir%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoProfile -ExecutionPolicy Bypass -file C:\\Config.ps1</CommandLine><Description>script</Description><Order>2</Order></SynchronousCommand></FirstLogonCommands>'
},
{
passName: 'oobeSystem',
componentName: 'Microsoft-Windows-Shell-Setup',
settingName: 'AutoLogon',
content: "[concat('<AutoLogon><Password><Value>', parameters('adminPassword'), '</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount><Username>', parameters('adminUserName'), '</Username></AutoLogon>')]"
}
]
}
EOH
end

def virtual_machine_deployment_template
Expand Down
2 changes: 2 additions & 0 deletions templates/internal.erb
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[variables('location')]",
<%- if public_ip -%>
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
],
<%- end -%>
"properties": {
"ipConfigurations": [
{
Expand Down