I am not clear on what you are asking for. You can run a playbook as any user ( that you have the credentials for ) Perhaps you could give more details on what it is you are asking for?
I have had issues with sudo / normal users causing conflicts. At first I made two copies of the playbook and had one with sudo, one without, but that is terrible for maintenance.
The per-task sudo: yes can be helpful for local actions, and per-task remote_user will be handy too. But for running entire playbooks as either sudo or root…
The problem i faced was that i sometimes run as root and sometimes as a sudo user, and unfortunately, unlike a unix shell where running a sudo command as root is fine, ansible errors out with something like
and pass in use_sudo as an extra var ala, ansible-playbook -i hosts site.yml --extra-vars=“use_sudo=yes”.
But it would be nice if ansible just made it possible to run sudo commands as root like normal unix.
Here is a more complete context of the problem i was trying to solve.
admin_user is the sometimes root, sometimes sudo user that can add new users. It failed until I added the “use_sudo” arg as outlined above.
Thanks everyone for suggestions (I was a bit away madly doing manual upgrades :)).
So far using different ‘remote_user’ for tasks that do not require special privileges and for those that do sounds exactly what I was looking for (sorry, Jim, I did not describe my problem better).
I was facing the same issue until i changed the privilges of normal user to ‘ALL’ in sudoers file. Now ansible playbook doesn’t asks for passwords for this user.