Notify handler as different user

Hi,

Long-time lurker, first time poster. First off, thanks for this excellent project.

I’d like to know, is it possible to run the ‘notify’ handler as a different user from the task which notified it? E.g.

Hello,

Have you just tried? : D .

I have tried it like this

  • name: restart nginx
    service: name=nginx state=restarted
    sudo_user: username

But have in mind that user must have permissions for the service.

P.S.

Im sorry for “spamming”, I have just tried the handler with sudo_user option to check if Ansible will call it. You cannot restart nginx as non root user.

Yep, and if you are not wanting to use sudo, you can set “remote_user” instead.

Holy crap, I can’t believe I didn’t try that earlier.

In my case, because project_user does not have root, I had to call remote_user instead.