Switching users between provisioners

12 views
Skip to first unread message

Christoffer Bjørk Pedersen

unread,
Dec 26, 2018, 12:30:16 PM12/26/18
to Packer
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:
  1. Install some packages, create a custom user and add them to a group, then
  2. 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!

Rickard von Essen

unread,
Dec 26, 2018, 12:59:27 PM12/26/18
to packe...@googlegroups.com
Just edit the command to do "sudo - u <user>", see https://www.sudo.ws/man/1.8.3/sudo.man.html

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/0f12e319-a7eb-409e-ae63-2e4887effe34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages