# Notify handler as different user

**URL:** <https://forum.ansible.com/t/notify-handler-as-different-user/14834>\
**Category:** Ansible Project\
**Created:** [March 23, 2014, 5:00pm UTC](https://forum.ansible.com/t/notify-handler-as-different-user/14834 "2014-03-23T17:00:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wei\_Yen\_Lee](https://avatars.discourse-cdn.com/v4/letter/w/dfb087/32.png) [@Wei\_Yen\_Lee](https://forum.ansible.com/u/Wei_Yen_Lee)\
**Post date:** [March 23, 2014, 5:00pm UTC](https://forum.ansible.com/t/notify-handler-as-different-user/14834/1 "2014-03-23T17:00:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Marko\_Lisica](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marko\_Lisica](https://forum.ansible.com/u/Marko_Lisica)\
**Post date:** [March 24, 2014, 3:07pm UTC](https://forum.ansible.com/t/notify-handler-as-different-user/14834/2 "2014-03-24T15:07:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Marko\_Lisica](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marko\_Lisica](https://forum.ansible.com/u/Marko_Lisica)\
**Post date:** [March 24, 2014, 3:15pm UTC](https://forum.ansible.com/t/notify-handler-as-different-user/14834/3 "2014-03-24T15:15:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 24, 2014, 3:19pm UTC](https://forum.ansible.com/t/notify-handler-as-different-user/14834/4 "2014-03-24T15:19:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wei\_Yen\_Lee](https://avatars.discourse-cdn.com/v4/letter/w/dfb087/32.png) [@Wei\_Yen\_Lee](https://forum.ansible.com/u/Wei_Yen_Lee)\
**Post date:** [March 25, 2014, 3:39pm UTC](https://forum.ansible.com/t/notify-handler-as-different-user/14834/5 "2014-03-25T15:39:54Z")

</div>

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.
