Switching Packer SSH user midway?

Does anyone know if its possible to switching to another SSH user in provisioner with the same key pair credentials?

I am trying to remove the default user from the base OS and switch to my custom user to continue provisioning.

In the ideal scenario in single packer pipeline, I’d want to

  • Spin up an instance with an official base OS (ie. Ubuntu)
  • SSH with the default “ubuntu” user
  • Within the instance, setup my new default user (ie. “ops123”)
  • Then in another provisioner, log back int he instance with my new default user (“ops123”) and remove the default “ubuntu” user

I could do this in two packer pipelines that will mean having to keep track of the base AMI with the default user removed and seems more efficient to do it all in one single pipeline.

This isn’t currently possible.

Perhaps you could do this using the Ansible provisioner, by using a different user for subsequent plays, defined in the playbook you’re using.