First of all, you really want to use sudo_user
(the remote user is the one who logs in, sudo_user
is the one who performs the task).
In your case, you want to complete the task as another user (previously created):
- include: moretasks.yml sudo: yes sudo_user: "{{ newuser }}"
and these tasks will be executed as {{newuser}} (do not forget the quotation marks)
Note. In most cases, you should consider remote_user
as a host parameter. The user can log on to the machine and has sufficient rights to perform actions. To work, you must use sudo
/ sudo_user
source share