Also I have gone through the logs and seems everything is executing just 
fine till the below part of the JSON

   {
      "type": "windows-restart",
      "restart_check_command": "powershell -command \"& {Write-Output 
'restarted.'}\""
    },


Which matches with this part of the log

2018/04/07 09:59:58 [INFO] (telemetry) ending powershell
*2018/04/07 09:59:58 [INFO] (telemetry) Starting provisioner 
windows-restart*
*2018/04/07 09:59:58 ui: ==> azure-arm: Restarting Machine*
2018/04/07 10:00:02 [INFO] 0 bytes written for 'stderr'
2018/04/07 10:00:02 [INFO] 0 bytes written for 'stdout'
2018/04/07 10:00:02 packer.exe: 2018/04/07 10:00:02 [INFO] 0 bytes written 
for 'stdout'
2018/04/07 10:00:02 packer.exe: 2018/04/07 10:00:02 [INFO] 0 bytes written 
for 'stderr'
2018/04/07 10:00:02 packer.exe: 2018/04/07 10:00:02 Retryable error: http 
response error: 401 - invalid content type
2018/04/07 10:00:08 [INFO] 0 bytes written for 'stderr'
2018/04/07 10:00:08 [INFO] 0 bytes written for 'stdout'

Then I am assuming packer is looking to perform the following and last bit 
of your JSON file

*"type": "powershell",*
*    "inline": [*
*      "Add-WindowsFeature Web-Server",*
*      "if( Test-Path 
$Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml ){ rm 
$Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml -Force}",*
*      "& $Env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize 
/quiet /quit"*
    *]*
*  }]*

And this is where the error of  *"**Retryable error: http response error: 
401 - invalid content type"* shows in the logs 

I reckon the issue is with *Add-WindowsFeature *which seems replaced by 
*Install-WindowsFeature* ( Source Link --> Install-WindowsFeature 
Documentation 
<https://docs.microsoft.com/en-us/powershell/module/servermanager/install-windowsfeature?view=winserver2012r2-ps>

Seems the *Add-WindowsFeature* content was used in Windows Server 2008 
R2... But not being an expert in Windows, I'd recommend you remove the last 
bit of your JSON file where you try to install/enable the windows server 
role... see whether packer fails or not, if that does not fail, then run 
the command shown below and see what is the output..


*"type": "powershell",*
*    "inline": [*
*      "Add-WindowsFeature Web-Server",*
*      "if( Test-Path 
$Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml ){ rm 
$Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml -Force}",*
*      "& $Env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize 
/quiet /quit"*
    *]*
*  }]*


On Tuesday, May 1, 2018 at 2:10:01 PM UTC+12, Gabo Kete wrote:
>
> HI Sim
>
> I do not have an Azure account to help you to test this.. but I went 
> through the documentation and to authorize Packer to build in Azure there 
> are 6 configuration options you will need ( Check this link --> Azure 
> Setup <https://www.packer.io/docs/builders/azure-setup.html> ) 
>
> I compared it with your JSON file and seems there are at least 2 missing ( 
> *resource_group_name* and *storage_account* ) 
>
>
>
> <https://lh3.googleusercontent.com/-co_G2t9bnzg/WufLF_Yt_pI/AAAAAAAAQVU/IZWTXEzgOF4q_A1DxV32g9H0m9TmPNSoQCLcBGAs/s1600/Screen%2BShot%2B2018-05-01%2Bat%2B2.02.07%2BPM.png>
>
>
>
>
>
>
>
>
>
>
>
>
> Also the link I shared above, tells you how to setup your packer 
> environment so can work with Azure plus gives you a couple of examples how 
> to do some testings .If you haven't installed the AZURE Cli, is part of 
> what you need to setup prior using packer..
>
> I will recommend to have a look at the link above and make sure you have 
> the environment setup prior using packer to deploy your VMs in AZURE..
>
> Let us know how it goes.. 
>
> Regards
>
>
>
>
>
>
>
>
>
>
> On Tuesday, May 1, 2018 at 1:18:35 PM UTC+12, Sim wrote:
>>
>> Hi @Gabo, 
>>
>> I don't think it's about my credential issue as I did run this PowerShell 
>> domain join with this credential in the new machine and it worked (added 
>> the new machine to the domain). Could you help me try to put the domain 
>> join Powershell script in the template like the above order and build it to 
>> see if you get the same issue as me (couldnt complete the packer build - 
>> everything after domain join execution just doesnt work). 
>>
>> This is the Packer JSON file that I use, feel free to replace anything 
>> after the powershell domain join (running other powershell script, restart 
>> VM,... ) as Packer just didnt do anything after the domain join thing. 
>>
>> {
>>   "variables": {
>>     "client_id": "{{env `AZURE_CLIENT_ID`}}",
>>     "client_secret": "{{env `AZURE_CLIENT_SECRET`}}",
>>     "tenant_id": "{{env `AZURE_TENANT_ID`}}",
>>     "subscription_id": "{{env `AZURE_SUBSCRIPTION_ID`}}",
>>     "object_id": "{{env `AZURE_OBJECT_ID`}}"
>>     },
>>   "builders": [{
>>     "type": "azure-arm",
>>
>>     "client_id": "{{user `client_id`}}",
>>     "client_secret": "{{user `client_secret`}}",
>>     "tenant_id": "{{user `tenant_id`}}",
>>     "subscription_id": "{{user `subscription_id`}}",
>>     "object_id": "{{user `object_id`}}",
>>
>>     "managed_image_resource_group_name": "MyPacker",
>>     "managed_image_name": "myPackerImage",
>>
>>
>>     "virtual_network_name": "------",               
>>     "virtual_network_subnet_name": "-----",       
>>     "virtual_network_resource_group_name": "Networking",
>>
>>     "os_type": "Windows",
>>     "image_publisher": "MicrosoftWindowsServer",
>>     "image_offer": "WindowsServer",
>>     "image_sku": "2016-Datacenter",
>>
>>     "disk_additional_size": "12",
>>
>>     
>>     "communicator": "winrm",
>>     "winrm_use_ssl": "true",
>>     "winrm_insecure": "true",
>>     "winrm_timeout": "10m",
>>     "winrm_username": "packer",
>>
>>     "azure_tags": {
>>         "dept": "Engineering",
>>         "task": "Image deployment"
>>     },
>>
>>     "location": "australiasoutheast",
>>     "vm_size": "Standard_DS2_v2"
>>   }],
>>   "provisioners": [
>>     {
>>       "type": "powershell",
>>       "inline": ["mkdir c:\\Packer"]
>>     },
>>     {
>>       "type": "file",
>>       "source": "ToUpload/",
>>       "destination": "c:\\Packer"
>>     },
>>     {
>>       "type": "windows-restart",
>>       "restart_check_command": "powershell -command \"& {Write-Output 
>> 'restarted.'}\""
>>     },
>>     {
>>       "type": "windows-restart",
>>       "restart_check_command": "powershell -command \"& {Write-Output 
>> 'restarted.'}\""
>>     },
>>     {
>>       "type": "powershell",
>>       "script": 
>>         "ToUpload/join_domain.ps1"
>>     },
>>     {
>>       "type": "windows-restart",
>>       "restart_check_command": "powershell -command \"& {Write-Output 
>> 'restarted.'}\""
>>     },
>>     {
>>     "type": "powershell",
>>     "inline": [
>>       "Add-WindowsFeature Web-Server",
>>       "if( Test-Path 
>> $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml ){ rm 
>> $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml -Force}",
>>       "& $Env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe 
>> /generalize /quiet /quit"
>>     ]
>>   }]
>> }
>>
>>
>>
>> Thanks so much, 
>>
>>

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/6d49e7aa-0002-4f08-ae46-cd5d5532ab53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to