hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.04k stars 3.32k forks source link

Please provide a way to refresh my ssh connection, or let me login/logout #12036

Open daraul opened 1 year ago

daraul commented 1 year ago

Community Note

Please search the existing issues for relevant feature requests, and use the reaction feature (https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to add upvotes to pre-existing requests.

Description

I want to be able to edit the packer user's groups, then tell packer to refresh the ssh connection so that I don't have to do any hacky business to get my permissions -- I want to be able to tell packer to logout, and login.

Use Case(s)

I am building an EC2 image with a docker image on it. I have to run the docker commands as sudo.

Potential configuration

  provisioner "shell" {
    inline = [
      "sudo usermod -a -G docker ec2-user"
    ]
  }
  # 2nd shell provisioner, that can be configured to refresh the connection
  provisioner "shell" {
    new_connection = true
    inline = [
      "docker run hello-world"
    ]
  }

Potential References

This was brought up in an old thread of google groups.

https://groups.google.com/g/packer-tool/c/XPXwk7PgLcc

matthiaskraaz commented 4 months ago

My workaround:

provisioner "shell" {
  script = ...
  execute_command = "sudo su -l docker -c '{{ .Vars }} {{ .Path }}'"
}
mixja commented 1 month ago

newgrp docker

https://docs.docker.com/engine/install/linux-postinstall/