hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder
https://www.packer.io/docs/builders/amazon
Mozilla Public License 2.0
76 stars 112 forks source link

Winrm and SSH Timeout: Packer build for both Linux and Windows based AWS Images #294

Closed itsrahul-cdw closed 2 years ago

itsrahul-cdw commented 2 years ago

When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.

Overview of the Issue

Facing the issue with both AWS Windows and Linux Ubuntu Images. They'are working fine on WinRM and SSH communicator if using public subnet but not for private subnet.

Why it is happenning that packer build stops at winRM and SSH from connecting and how to prevent timeouts from occurring?

A paragraph or two about the issue you're experiencing.

Reproduction Steps

Launch the template and attempt to create AWS AMI using packer build command

Plugin and Packer version

1.8.2

Simplified Packer Buildfile

packer { required_plugins { amazon = { version = ">= 1.1.1" source = "github.com/hashicorp/amazon" } } }

variable "debug" { type = bool default = true }

variable "communicator" { type = string default = "ssh" }

variable "aws_access_key" { type = string sensitive = true default = "" }

variable "aws_secret_key" { type = string sensitive = true default = "" }

variable "ssh_username" { type = string default = "" }

variable "pause_before_connecting" { type = string default = "2m" }

source "amazon-ebs" "ubuntu-test" { communicator = var.communicator access_key = var.aws_access_key secret_key = var.aws_secret_key ssh_username = var.ssh_username associate_public_ip_address = false ssh_interface = "private_ip" ami_name = "ubuntu-test-22.04-hvm-ebs-{{timestamp}}" pause_before_connecting = var.pause_before_connecting instance_type = "t2.micro" region = "us-east-1" vpc_id = "vpc-##############" subnet_id = "subnet-################" source_ami_filter { filters = { name = "ubuntu/images/ubuntu-test-22.04-amd64-server-" root-device-type = "ebs" virtualization-type = "hvm" } most_recent = true owners = ["099720109477"] } skip_create_ami = "${var.debug}" # true when debugging, false in production }

build { name = "ubuntu-test" sources = [ "source.amazon-ebs.ubuntu-test" ]

provisioner "shell" { inline = ["apt-get update -y"] execute_command = "echo 'ubuntu' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" } }

Operating system and Environment details

The EC2 is Ubuntu 22-04

Log Fragments and crash.log files

==> ubuntu-test-amazon-ebs.ubuntu-test: Waiting for instance (i-###############) to become ready... ubuntu-test.amazon-ebs.ubuntu-test Private IP: ##.##.##.##

==> ubuntu-test-amazon-ebs.ubuntu-test: Pausing after run of step 'StepRunSourceInstance'. Press enter to continue. ==> ubuntu-test.amazon-ebs.ubuntu-test: Pausing after run of step 'StepGetPassword'. Press enter to continue. ==> ubuntu-test.amazon-ebs.ubuntu-test: Pausing after run of step 'StepCreateSSMTunnel'. Press enter to continue. ==> ubuntu-test.amazon-ebs.ubuntu-test: Using SSH communicator to connect: ##.##.##.## ==> ubuntu-test.amazon-ebs.ubuntu-test: Waiting for SSH to become available... ==> ubuntu-test.amazon-ebs.ubuntu-test: Timeout waiting for SSH.

Set the env var PACKER_LOG=1 for maximum log detail.

nandu-b commented 2 years ago

when using winrm as communicator, do not use ssh. This should resolve the issue

itsrahul-cdw commented 2 years ago

I know that WinRM is to be used with Windows based Images and ssh for Linux ones. Can you please confirm if bootstrap script is neccessary to ready winrm configuration in case of secure HTTPS communication on port 5986?

nandu-b commented 2 years ago

No, not necessary