Adding additional user and application to Packer (build.json)


I have finally managed to get Packer working on my home VMware ESXi 7 lab, it builds an Ubuntu 18.0.4 VM.




Now I want to build on this. The user I build into the script to log in with is ‘vagrant’, I just used this from a template I found online, how do I script it to change this to something else or add a new user with root permissions and delete vagrant?

Lastly I how would I install some extra tools/software?


You can create an additional user and grant sudo permissions in your preseed. I can post an example later this day… Just give me some time. :slight_smile:

The extra tools are installed using a provisioner. Or in the preseed this should be possible, too, I guess.

That would be amazing thanks.

I’m loving Packer, I need to understand my preseed file better as I used a template, but not knowing fully what some parts do in it.

Also I need to see why some use the provisioner section or preseed file to add extra tools.

For an additional account using preseed:

d-i passwd/username string <your-username>
d-i passwd/user-fullname string <your-username>
d-i passwd/user-password-crypted password <encrypted-password>
# setup passwordless sudo (temporary)
d-i preseed/late_command string \
  echo "%<your-username> ALL=(ALL:ALL) ALL" > /target/etc/sudoers.d/<your-username> ; \
  in-target chmod 0440 /etc/sudoers.d/<your-username> ;

For the password encryption you could use:

mkpasswd -m sha-512 -S $(pwgen -ns 16 1) <your-password>

For package installation using preseed:

pkgsel/include string <your-package>

Personally I am only installing openssh-server in the preseed file, so the installer has less to do and the ETA is smaller. I don’t know the advantages/ disadvantages of either using preseed or provisioner for tools installation. :eyes:

1 Like