Although Ansible with packer always connects as the default user, my scripts have a need to refer to that user as a var, which is different for the multiple builds. Is it possible to pass through the current user as a variable? eg:
If I understand correctly, you need to reference the user which is currently connected to the instance you are provisioning, within the playbook, right?
This is contained in an internal Ansible variable : ansible_user:
’ ansible_user’
The user Ansible ‘logs in’ as.
You should be able to look it up during the execution of a task by passing {{ ansible_user }}.
My ansible is pretty rusty, but I’m repeating myself in this packer code when it comes to specifying different users based on the ami target. Is it possible to handle variables dynamically based on the target image? in each case the user to connect as is different between rocky and ec2-user. Does packer itself support dynamic vars based on the target ami?