Run one simple coomand with sudo priviliges.

19 views
Skip to first unread message

Dawid D

unread,
May 22, 2018, 8:40:20 AM5/22/18
to Ansible Project
Hello All,
    I would like ask about privileges escalation by sudo.

    I need run command on RemoteMachine. User: someone and Command: /usr/local/blah.sh for example
  
    suoders file:
someone RemoteMachine =(root)/usr/local/blah.sh

    Unfortunately I can't give permission to switch root, and I can't give NOPASSWD phrase in sudoers.

    I tried by:
shell: /usr/local/blah.sh
become: yes
become_method: sudo
 
    But it is failed because ansible trying switch to user before run command.

    I tried also:
shell: "sudo /usr/local/blah.sh"
  
    But this one hanging ansible, because he is waiting for sudo password.

    Is there any possibility to just run command with sudo and provide password automatically ?

    I will be very happy for help.

Than you Ansible community,
Regards Dawid D.

Kai Stian Olstad

unread,
May 22, 2018, 2:08:45 PM5/22/18
to ansible...@googlegroups.com
On 22.05.2018 14:40, Dawid D wrote:
> Hello All,
> I would like ask about privileges escalation by sudo.
>
> I need run command on *RemoteMachine*. *User: someone* and
> *Command:
> /usr/local/blah.sh *for example
>
> suoders file:
> someone RemoteMachine =(root)*/usr/local/blah.sh*
>
> Unfortunately I can't give permission to switch root, and *I can't
> give*
> NOPASSWD phrase in sudoers.
>
> I tried by:
> shell: /usr/local/blah.sh
> *become: yes*
> *become_method: sudo*
>
> But it is failed because ansible trying switch to user before run
> command.

This, the shell module, actually run "sudo /some/python/script" and that
script run plain "/usr/local/blah.sh"


> I tried also:
> shell: "*sudo* /usr/local/blah.sh"
>
> But this one hanging ansible, because he is waiting for sudo
> password.
>
> Is there any possibility to just run command with sudo and provide
> password automatically ?

sudo do support -S for reading the password from stdin.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages