2

Packer seems to fail at the Amazon Scripts to sysprep the machine. I have tried a bunch of different things. Putting the scripts in their own script, running, them 'inline' like many people show but nothing seems to work. I keep getting the following error:

Build 'amazon-ebs' errored: Error processing command: Retryable error: Error uploading ps script containing env vars: Error uploading file to $env:TEMP\winrmcp-10fca0b1-a0ac-47d2-7462-77d91b066859.tmp: Couldn't create shell: http response error: 401 - invalid content type

Any help would be greatly appreciated.

Packer version: Packer v1.3.3

Below is my packer JSON:

    {
  "builders": [
    {
      "type": "amazon-ebs",
      "ami_description": "Base Win2016 with encrypted root",
      "ami_name": "examsoft-win2016-{{timestamp}}",
      "ami_regions": [
        "us-east-2",
        "ap-southeast-1",
        "us-east-1",
        "us-west-2"
      ],
      "encrypt_boot": true,
      "instance_type": "t2.micro",
      "region": "us-east-2",
      "user_data_file": "./bootstrap_win.txt",
      "communicator": "winrm",
      "winrm_username": "Administrator",
      "winrm_password": "{{user `winrm_password` }}",
      "region_kms_key_ids": {
        "ap-southeast-1": "alias/aws/ebs",
        "us-east-1": "alias/aws/ebs",
        "us-east-2": "alias/aws/ebs",
        "us-west-2": "alias/aws/ebs"
       },
      "source_ami_filter": {
        "filters": {
          "virtualization-type": "hvm",
          "name": "*Windows_Server-2016-English-Full-Base*",
          "root-device-type": "ebs"
        },
        "owners": "amazon",
        "most_recent": true
      }
    }
  ],

  "description": "Base Windows 2016 image with manager credentials and encrypted root",

  "provisioners": [

    {
      "type": "powershell",
      "script": "./scripts/ConfigureRemotingforAnsible.ps1"
    },

    {
      "type": "powershell",
      "script": "./scripts/ConfigurePackerImage.ps1"
    },

    {
      "type": "powershell",
      "inline": [
        "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeInstance.ps1 -Schedule",
        "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SysprepInstance.ps1 -NoShutdown"
      ]
    }
  ]
}
tingels
  • 21
  • 3

1 Answers1

1

I came across this exact error and my issue was that I was changing the Administrator password in a script that was executed in the provisioner prior to running sysprep.

Are you changing the Administrator password in ./scripts/ConfigurePackageImage.ps1?

If so, I ripped out the code that changes the Administrator's account password and I'm now running it in a separate script that gets executed in a provisioner after sysprep.

German
  • 111
  • 1