Ansible SSH "stderr": "reboot: Need to be root"

34 views
Skip to first unread message

Hemant Kulkarni

unread,
Feb 28, 2018, 12:10:08 AM2/28/18
to Ansible Project
Hello Team,

I need to  reboot my servers using ansible ,my Problem is  i dont have sudo user , i have normal user and root password ..

admin = normal user 

here is my simple playbook ...

- hosts: unix
  tasks:
  - name: reboot servers
    command: /sbin/reboot

as of now I tried below Option 

ansible-playbook packge_install.yum  -i hosts  --su-user=root  --ask-su-pass
ansible-playbook packge_install.yum  -i hosts --user=admin --ask-pass --su --ask-su-pass

but its not working ... any idea How to achieve this ?

regards...Hemant 



Kai Stian Olstad

unread,
Feb 28, 2018, 3:05:04 AM2/28/18
to ansible...@googlegroups.com
On 28.02.2018 06:10, Hemant Kulkarni wrote:
> I need to reboot my servers using ansible ,my Problem is i dont have
> sudo
> user , i have normal user and root password ..
>
> admin = normal user
>
> here is my simple playbook ...
>
> - hosts: unix
> tasks:
> - name: reboot servers
> command: /sbin/reboot

You could change your playbook to

- hosts: unix
become: yes
become_method: su
tasks:
- name: reboot servers
command: /sbin/reboot

Then you can run

ansible-playbook packge_install.yum -i hosts --ask-become-pass


> as of now I tried below Option
>
> ansible-playbook packge_install.yum -i hosts --su-user=root
> --ask-su-pass
> ansible-playbook packge_install.yum -i hosts --user=admin --ask-pass
> --su
> --ask-su-pass
>
> but its not working ... any idea How to achieve this ?

If you would like to keep the playbook as is, this should work

ansible-playbook packge_install.yum -i hosts --become-method=su --become
--ask-become-pass


You also have the short version of the options, check
anible-playbook -h

--
Kai Stian Olstad

Hemant Kulkarni

unread,
Feb 28, 2018, 7:48:35 AM2/28/18
to Ansible Project
Thanks for your Views ... I tried that but it seem same error ... 

below is my playbook 

.
---
- hosts: unix
  become: yes
  become_method: su
  tasks:
  - name: reboot servers
    command: /sbin/reboot


error --

TASK [reboot servers] ***************************************************************************************************************************************
fatal: [192.168.1.10]: FAILED! => {"changed": true, "cmd": ["/sbin/reboot"], "delta": "0:00:00.014962", "end": "2018-02-28 18:11:20.468716", "failed": true, "rc": 1, "start": "2018-02-28 18:11:20.453754", "stderr": "reboot: Need to be root", "stderr_lines": ["reboot: Need to be root"], "stdout": "", "stdout_lines": []}


regards...Hemant 

Hemant Kulkarni

unread,
Feb 28, 2018, 11:29:28 AM2/28/18
to Ansible Project
Hello,

Just an Update , I did small change in my Play boot ...

---
- hosts: unix
  become: true
  become_method: su
  become_user: root
  tasks:
  - name: reboot servers
    command: /sbin/reboot

it seem to working  ... any way thanks for looking in to it ....

On Wednesday, February 28, 2018 at 10:40:08 AM UTC+5:30, Hemant Kulkarni wrote:
Reply all
Reply to author
Forward
0 new messages