Сборка Windows EC2 образа с упаковщиком - PullRequest
0 голосов
/ 29 апреля 2020

при запуске сборки упаковщика, я получаю сообщение об ошибке при Waiting for WinRM to become available... и сбой через 15 минут. Любые предложения, пожалуйста!

Я использую packer -version --> 1.5.5

Запуск сборки упаковщика как packer build packer-aws-windows-ami.json

Подробности приведены ниже: -

Журналы выполнения:

amazon-ebs: output will be in this color.

==> amazon-ebs: Prevalidating any provided VPC information
==> amazon-ebs: Prevalidating AMI Name: Nigam-Packer-Win2016-Test
    amazon-ebs: Found Image ID: ami-0b2ce977c1b36856d
==> amazon-ebs: Creating temporary keypair: packer_5ea79a20-dd01-a7d5-6760-xa134e097ff1
==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Adding tags to source instance
    amazon-ebs: Adding tag: "Name": "Packer Builder"
    amazon-ebs: Instance ID: i-025xebcexa6b7cc28
==> amazon-ebs: Waiting for instance (i-025xebcexa6b7cc28) to become ready...
==> amazon-ebs: Skipping waiting for password since WinRM password set...
==> amazon-ebs: Using winrm communicator to connect: 16.226.144.187
==> amazon-ebs: Waiting for WinRM to become available...
==> amazon-ebs: Timeout waiting for WinRM.
==> 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 keypair...
Build 'amazon-ebs' errored: Timeout waiting for WinRM.

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: Timeout waiting for WinRM.

==> Builds finished but no artifacts were created.

упаковщик- aws - windows -ами. json

{
  "variables": {
    "build_version": "{{isotime \"2020.04.29.103307\"}}",
    "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
    "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
    "region": "us-east-2",
    "instance_type": "t3.large",
    "vpc_id": "myvpc",
    "subnet_id": "mysubnet",
    "ssh_keypair_name": "./key.pem",
    "security_group_id": "sg-id",
    "user_data_file": "userdata.txt",
    "name": "Packer_AMI_TEST"
  },
  "builders": [
      {
        "type": "amazon-ebs",
        "access_key": "{{ user `aws_access_key` }}",
        "secret_key": "{{ user `aws_secret_key` }}",
        "region": "{{ user `region` }}",
        "ami_name": "Test_Packer-Win-{{timestamp}}",
        "source_ami_filter": {
          "filters": {
            "name": "Windows_Server-2016-English-Full-Base-*",
            "root-device-type": "ebs",
            "virtualization-type": "hvm" },
          "most_recent": true,
          "owners": ["amazon"]
        },
        "instance_type": "{{user `instance_type`}}",
        "vpc_id": "{{user `vpc_id`}}",
        "subnet_id": "{{user `subnet_id`}}",
        "security_group_id": "{{user `security_group_id`}}",
        "user_data_file": "{{user `user_data_file`}}",
        "ami_name": "Nigam-Packer-Win2016-Test",
        "ssh_private_key_file": "{{user `ssh_keypair`}}",
        "associate_public_ip_address": true,
        "communicator": "winrm",
        "winrm_username": "Administrator",
        "winrm_password": "SuperS3cr3t!",
        "winrm_timeout": "15m",
        "winrm_use_ssl": true,
        "winrm_insecure": true
      }
  ],
  "provisioners": [
    {
      "type": "powershell",
      "inline": [
        "Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole",
        "Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer"
      ]
    },
    {
      "type": "windows-restart",
      "restart_check_command": "powershell -command \"& {Write-Output 'Machine restarted.'}\""
    },
    {
      "type": "powershell",
      "inline": [
        "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\InitializeInstance.ps1 -Schedule",
        "C:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Scripts\\SysprepInstance.ps1 -NoShutdown"
      ]
    }
]

}

userdata.txt

# Create username and password
net user Administrator SuperS3cr3t!!!
wmic useraccount where "name='Administrator'" set PasswordExpires=FALSE

Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore

# Don't set this before Set-ExecutionPolicy as it throws an error
$ErrorActionPreference = "stop"

# Remove HTTP listener
Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse

# Create a self-signed certificate to let ssl work
$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer"
New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force

# WinRM
write-output "Setting up WinRM"
write-host "(host) setting up WinRM"

# Configure WinRM to allow unencrypted communication, and provide the
# self-signed cert to the WinRM listener.
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm set "winrm/config/service" '@{AllowUnencrypted="true"}'
cmd.exe /c winrm set "winrm/config/client" '@{AllowUnencrypted="true"}'
cmd.exe /c winrm set "winrm/config/service/auth" '@{Basic="true"}'
cmd.exe /c winrm set "winrm/config/client/auth" '@{Basic="true"}'
cmd.exe /c winrm set "winrm/config/service/auth" '@{CredSSP="true"}'
cmd.exe /c winrm set "winrm/config/listener?Address=*+Transport=HTTPS" "@{Port=`"5986`";Hostname=`"packer`";CertificateThumbprint=`"$($Cert.Thumbprint)`"}"

# Make sure appropriate firewall port openings exist
cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes
cmd.exe /c netsh firewall add portopening TCP 5986 "Port 5986"

# Restart WinRM, and set it so that it auto-launches on startup.
cmd.exe /c net stop winrm
cmd.exe /c sc config winrm start= auto
cmd.exe /c net start winrm

1 Ответ

0 голосов
/ 29 апреля 2020

Я предполагаю, что упаковщик не может подключиться к экземпляру, созданному в VP C, или сценарий пользовательских данных не запускается при запуске.

Чтобы проверить подключение, вы можете запустить packer build -debug packer.json и он остановитесь на каждом шаге, чтобы вы могли проверить, можете ли вы подключиться к экземпляру с компьютера, на котором выполняется упаковщик.

Чтобы проверить второе предположение, вы можете запустить экземпляр с тем же базовым AMI без user- данные. Затем попробуйте подключиться к нему через RDP и, если вы в, отладить скрипт. Вы можете попробовать проверить его на официальном AWS AMI с той же версией Windows.

...