Dear Team,
I’m trying to build a windows 2016 ami from AWS Marketplace image. As part of it, I’m executing CIS hardening and also my requirement is to disable “Administrator” account. I’m doing all these hardening stuffs using ansible provisioner.
Achieved everything and It is working fine without any issue. But at the end, there are 2 command lines to be executed under powershell for System Initialization and Sysprep before converting the instance into an image.
Powershell commands:
{
“type”: “powershell”,
“elevated_user”: “Testuser”,
“elevated_password”: “Password”,
“inline”: [
“C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -SchedulePerBoot”,
“C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1 -NoShutdown”
]
}
I’m executing these above commands using an elevated_user account but it is failing with the below error messages. Could you please help on this? Does these commands only be executed under Administrator user account? or how it could be handled.
Errors:
rs: Error uploading file to $env:TEMP\winrmcp-7eb4bb9c-36eb-4655-6066-5f2beaf938b9.tmp: Couldn’t create shell: http response error: 401 - invalid content type
2021/03/17 08:18:11 packer-provisioner-powershell plugin: [INFO] 0 bytes written for ‘uploadData’
2021/03/17 08:18:11 [INFO] 0 bytes written for ‘uploadData’
2021/03/17 08:18:11 packer-builder-amazon-ebs plugin: Uploading file to ‘c:/Windows/Temp/packer-ps-env-vars-6051b871-0597-6142-3acd-6091cc93b454.ps1’
2021/03/17 08:18:11 packer-provisioner-powershell plugin: Retryable error: Error uploading ps script containing env vars: Error uploading file to $env:TEMP\winrmcp-fd774a08-b1f7-4517-4ec9-6f757ba9499b.tmp: Couldn’t create shell: http response error: 401 - invalid content type
2021/03/17 08:18:13 packer-provisioner-powershell plugin: [INFO] 0 bytes written for ‘uploadData’
2021/03/17 08:18:13 [INFO] 0 bytes written for ‘uploadData’
2021/03/17 08:18:13 packer-builder-amazon-ebs plugin: Uploading file to ‘c:/Windows/Temp/packer-ps-env-vars-6051b871-0597-6142-3acd-6091cc93b454.ps1’
Regards,
Guru Mohan Gwin-ami-build-template.txt (1.7 KB)