Recently started using ansible. We have servers where the application is setup under different users, like in server xyz.com, unix user is xyz_user and so on.
So in case of xyz.com,
ansible xyz.com -a 'command' -u xyz_user -K
How can we set the sudo user in ansible config so as to automatically sudo to the particular user defined for the server?
I would recommend using host variables based on the inventory or group vars. This allows you to set the ssh user per host or per group of hosts. The advantage of this approach is that it's transparent to your playbooks. In the playbooks you then only have to worry about installing things and not access.
An example on how to set the user by host and group:
And here is the documentation that explains how it works much better than me : http://docs.ansible.com/intro_inventory.html
You can leverage the ansible playbooks for these kind of stuffs.
e.g.
Hope it works for you :)