I'm new to Packer, and it seems awesome so far although I'm running into a few difficulties.
I need to create custom Debian images for AWS and Azure. I would like to use the provisioners to:
- Install some packages, create a custom user and add them to a group, then
- switch to that user to run rbenv and install some gems, so that they will be associated with that user and group rather than root.
The first part works fine as
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"
makes me root. Switching to the user for:
. /etc/profile.d/rbenv.sh
RUBY_CONFIGURE_OPTS=--disable-install-doc rbenv install 2.4.1
rbenv global 2.4.1
fails; if I use the same execute_command then the user remains root, even with commands like "su user whoami" . Without the execute_command the Debian user for my base image is admin, and I can't switch with su - user as I'm not in a terminal. ssh_pty=true doesn't help - it hangs on "exec bash --login", needed for my $PATH to work.
Is there a better execute_command I can use to run scripts as my custom user, or open a different SSH session as my custom user, or some other workaround?
Thank you!