I am using Packer to create a custom Virtual Machine. I would like to use the post-processor after the build is finished. I am trying to keep it simple, using inline commands. However, some of them require sudo. This is the problem I am facing - I can't seem to make the execute_command work properly.
Currently what I have is:
"post-processors": [
{
"type":"shell-local",
"execute_command": "echo 'password' | sudo",
"inline": ["command 1", "command 2", "sudo command 3"]
}
]
This results in:
==> vmware-iso: Running post-processor: shell-local
==> vmware-iso (shell-local): Post processing with local shell script: /tmp/packer-shell867480064
vmware-iso (shell-local): usage: sudo -h | -K | -k | -V
vmware-iso (shell-local): usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
vmware-iso (shell-local): usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
vmware-iso (shell-local): [command]
vmware-iso (shell-local): usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
vmware-iso (shell-local): prompt] [-u user] [VAR=value] [-i|-s] [<command>]
vmware-iso (shell-local): usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
vmware-iso (shell-local): prompt] [-u user] file ...
Does anyone have an idea how I should implement the execute_command to make it work?
Instead if you need to run passwordless (
NOPASSWD
) sudo configure sudo to allow it. Also verify if you need!requiretty
. See sudoers.conf.