We provision our servers in a cloud provider. The provider injects ssh keys and create a temp user for our initial connection.
We use that temp user to provision the machine and then the temp user will be disabled.
So the next run for plays will fail because remote_user does not exist anymore.
Any ideas how we might tackle this in an automated way?
I have provisioning playbooks (AWS) that create the server. They then
use add_host to add it to the inventory.
When using add_host you can pass other variables along that act just
like host_vars that came from the inventory (AFAIK).
If you pass the ansible_ssh_user you can set the user that ansible
uses for the remainder of that play to access that
host.
You can also add the host to any applicable groups. This is where I
then do my boostrapping of the host and the application of it's
necessary roles.
Then when you run another playbook later, the host is now in the
dynamic inventory and picks up the new real username that works after
the bootstrapping has been applied.
There's probably other ways to do it, but that's worked pretty well so far.