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.

---
  # webapp/handler/main.yml
  # This should be run as root
  - name: Restart supervisord
    supervisorctl: name={{ item }}
                   state=restarted
    remote_user: <user_with_sudo_privilege>
    sudo: True
    with_items:
    - celeryd
    - celerybeat

Thanks a lot guys!

On Monday, March 24, 2014 11:19:06 PM UTC+8, Michael DeHaan wrote:
>
> Yep, and if you are not wanting to use sudo, you can set "remote_user" 
> instead.
>
>
> On Mon, Mar 24, 2014 at 11:07 AM, Marko Lisica 
> <[email protected]<javascript:>
> > wrote:
>
>> 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.
>>
>>
>>
>> On Sunday, March 23, 2014 6:00:20 PM UTC+1, Wei Yen Lee wrote:
>>>
>>> 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.
>>>
>>> ---
>>>   # deploy.yml
>>>   - hosts: webservers
>>>     remote_user: project_user
>>>     roles:
>>>       - webapp
>>>
>>> ---
>>>   # webapp/tasks/main.yml
>>>   # This should be run as project_user
>>>   - name: Pull sources from the repository.
>>>     git: repo={{project_repo}}
>>>          dest={{project_root}}
>>>          version={{branch}}
>>>     notify:
>>>       - Restart supervisord
>>>
>>> ---
>>>   # webapp/handler/main.yml
>>>   # This should be run as root
>>>   - name: Restart supervisord
>>>     supervisorctl: name={{ item }}
>>>                    state=restarted
>>>     with_items:
>>>     - celeryd
>>>     - celerybeat
>>>
>>>
>>>
>>> If it's not possible, what's the best way to structure the project?
>>>
>>> Thanks in advance!
>>>  
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/922d3715-bf71-419d-a138-8465bda26564%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/922d3715-bf71-419d-a138-8465bda26564%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/88bb583e-7b38-4cbb-a99f-6b85104357bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to