YaleUniversity / packer-plugin-goss

Goss Provisioner for Packer
MIT License
136 stars 45 forks source link

Running into issue while Testing Windows AMI #52

Closed ranopriyo-neogy closed 8 months ago

ranopriyo-neogy commented 3 years ago

I am trying to create a Microsoft Windows Server 2016 Base AMI and use Goss for testing it. The same configuration worked fine when I launched Amazon Linux base AMI. However it fails provisioning Goss when I use it for Windows. Am I missing something for Windows server tests using Goss (below scenario).

My Template:

{
  "sensitive-variables": ["aws_access_key", "aws_secret_key", "token", "winrm_username_env", "winrm_password_env"],

  "builders": [{
      "type"                : "amazon-ebs",
      "access_key"          : "{{ user `aws_access_key` }}",
      "secret_key"          : "{{ user `aws_secret_key` }}",
      "token"               : "{{ user `token`}}",

      "region"              : "{{ user `region` }}",
      "instance_type"       : "t2.micro",
      "source_ami"          : "ami-xxx",
      "ami_name"            : "windows-ami-packer--{{timestamp}}",
      "winrm_username"      : "{{ user `winrm_username_env`}}",
      "user_data_file"      : "C:/Users/name/Desktop/packer-build-windows-ami/scripts/bootstrap_win.txt",
      "communicator"        : "winrm",
      "tags":{
        "Name": "windows-image- {{timestamp}}"
        }

  }],

  "provisioners": [
    {
      "type"                : "windows-restart"
    },

    {
      "script": "C:/Users/name/Desktop/packer-build-windows-ami/scripts/scripts.ps1",
      "type": "powershell"
    },

    {
      "type": "powershell",
      "environment_vars": ["WINRMUSER={{ user `winrm_username_env`}}", "WINRMPASS={{ user `winrm_password_env`}}"],
      "inline": [
        "net user $Env:WINRMUSER $Env:WINRMPASS"
      ] 
    },
    {
      "type": "goss",
      "tests": [
        "C:/Users/name/Desktop/packer-build-windows-ami/goss/goss.yaml"
      ]
    }
  ]
}

Error:

==> amazon-ebs: Provisioning with Powershell...
==> amazon-ebs: Provisioning with powershell script: C:\Users\name\AppData\Local\Temp\powershell-provisioner014273411
    amazon-ebs: The command completed successfully.
    amazon-ebs:
==> amazon-ebs: Provisioning with Goss
==> amazon-ebs: Configured to run on Linux
    amazon-ebs: Creating directory: /tmp/goss
==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored after 8 minutes 33 seconds: Error creating remote directory: http response error: 401 - invalid content type

==> Wait completed after 8 minutes 33 seconds

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: Error creating remote directory: http response error: 401 - invalid content type
jsturtevant commented 2 years ago

You don't have it configured properly for Windows. The out includes Configured to run on Linux.

You need to set the target_os in the provisioner config and the GOSS_USE_ALPHA flag to 1 see: https://github.com/YaleUniversity/packer-provisioner-goss#windows-support

An example configuration can be found at https://github.com/kubernetes-sigs/image-builder/blob/e56122226e1447eb21327f2ac4f98bde0e422b83/images/capi/packer/azure/packer-windows.json#L138

btassone commented 8 months ago

marking this as closed since no follow up