Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing Powershell Script Hangs Over Windows SSH #13228

Closed
grochoge opened this issue Dec 12, 2024 · 2 comments
Closed

Executing Powershell Script Hangs Over Windows SSH #13228

grochoge opened this issue Dec 12, 2024 · 2 comments
Labels

Comments

@grochoge
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

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

Overview of the Issue

Connecting to Windows over ssh leaving the default shell (cmd.exe) and attempting to run a Powershell script results in executing getting stuck.

It appears the default execute command is cutting off the Powershell arguments due to using an ampersand (&).

Reproduction Steps

  1. Launch Packer on a AWS EBS target with OpenSSH setup by EC2Luanchv2 using the following UserData
version: 1.1
tasks:
  - task: enableOpenSsh
  1. Execute the powershell providioner with a script file specified.
  2. Execution hangs

I see sshd.exe has launched:
c:\windows\system32\cmd.exe /c powershell -executionpolicy bypass & { if (Test-Path variable:global:ProgressPreference){set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'};. c:/Windows/Temp/packer-ps-env-vars-675b4cad-258a-9559-524d-13dd7c6a4d0b.ps1; &'c:/Windows/Temp/script-675b4cad-9a55-e618-7ab5-50c56aa62596.ps1'; exit $LastExitCode }

Which has launched
powershell -executionpolicy bypass

Packer version

Packer v1.11.2

Simplified Packer Template

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

source "amazon-ebs" "TemplateName" {
  ami_name      = "TemplateName"
  ami_virtualization_type = "hvm"
  communicator  = "ssh"
  ssh_timeout   = "25m"
  ssh_username  = "Administrator"
  ssh_interface = "private_ip"
  ssh_pty       = true
  instance_type = "c6i.large"
  region        = "us-east-1"
  decode_authorization_messages = true

  no_ephemeral = true
  launch_block_device_mappings {
    device_name = "/dev/sda1"
    volume_size = 60
    volume_type = "gp3"
    delete_on_termination = true
  }

  iam_instance_profile = var.iam_profile

  source_ami_filter {
    filters = {
      name                = "Windows_Server-2019*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["amazon"]
  }
  subnet_filter {
    filters = {
          "tag:Name": "TheSubnet"
    }
  }
  security_group_filter {
    filters = {
      "tag:Name": "TheSecurityGroup"
    }
  }

  user_data_file = "files/initial-userdata.yml"
  aws_polling {
    delay_seconds = 30
    max_attempts = 100
  }
}

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

  provisioner "powershell" {
    script   = "files/install-components.ps1"
  }
}

Operating system and Environment details

Windows 10 AMD64, building for Windows Server 2019 AMD64

Log Fragments and crash.log files

Windows PowerShell
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:
    TemplateName.amazon-ebs.TemplateName:

Include appropriate log fragments. If the log is longer than a few dozen lines,
please include the URL to the gist of the log or
use the Github detailed format instead of posting it directly in the issue.

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

@grochoge grochoge added the bug label Dec 12, 2024
@grochoge
Copy link
Author

The issue was ssh_pty = true which I believe I added previously to work around a bug that's since been fixed. Removing that line fixes the issue.

@grochoge grochoge closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant