yum state=absent leads to "you need to be root to perform this command"

1,622 views
Skip to first unread message

Paul Davies

unread,
Jan 14, 2016, 11:31:26 AM1/14/16
to Ansible Project
Hi - I'm new to Ansible and struggling

I have 2 playbooks for training/demo purposes. One to install Tree and Nano and another to remove them again. My control and destination servers are both Centos7

My webservers_latest.yml playbook for installing is...

---
- hosts webservers
  remote_user: myuser
  tasks:
  - name: ensure tree is at the latest version
    yum:
      name: tree
      state: latest
  - name: ensure nano is at the latest version
    yum:
      name: nano
      state: latest

This works absolutely fine. when run with ansible-playbook webservers_latest.yml I am asked for sudo password and it completes OK. However when I try to run this webservers_absent.yml playbook to remove tree and nano....

---
- hosts webservers
  remote_user: myuser
  tasks:
  - name: ensure tree is absent
    yum:
      name: tree
      state: absent
  - name: ensure nano is absent
    yum:
      name: nano
      state: absent

I get 
failed: [myuser@ipaddress] => {"changed": false, "failed": true, "rc": 1, "results": ["Loaded plugins: fastestmirros\n"]}
msg: You need to be root to perform this command.
FATAL: all hosts have already failed -- aborting

I can perform the sudo yum remove nano tree manually on the destination host without problem. I have tried all sorts of combinations of sudo_user: myuser, sudo: yes etc but I get the same result. What, presumably, obvious thing am I missing here?
Thanks

Paul Davies

unread,
Jan 14, 2016, 11:32:22 AM1/14/16
to Ansible Project
I should add that this is Ansible 1.9.4

Brian Coca

unread,
Jan 14, 2016, 12:13:44 PM1/14/16
to Ansible Project
can you run both with -vvvv to see what Ansible is doing? also show
the command line invocation of both playbooks.

On Thu, Jan 14, 2016 at 11:32 AM, Paul Davies <em...@pauldavies.me.uk> wrote:
> I should add that this is Ansible 1.9.4
>
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c18038e6-7851-41ab-b64e-f70a058e719c%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Paul Davies

unread,
Jan 15, 2016, 3:52:00 AM1/15/16
to Ansible Project
Hi Brian

from /etc/ansible I am running ansible-playbook webservers_absent.yml

with -vvvv I get

SUDO password:

PLAY [webservers] *************************************************************

GATHERING FACTS ***************************************************************
<myuser@ipaddress> ESTABLISH CONNECTION FOR USER: myuser
<myuser@ipaddress> REMOTE_MODULE setup
<myuser@ipaddress> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/myuser/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/home/myuser/.ssh/id_rsa" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10  /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110 && echo $HOME/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110'
<myuser@ipaddress> PUT /tmp/tmp4cBgiH TO /home/myuser/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110/setup
<myuser@ipaddress> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/myuser/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/home/myuser/.ssh/id_rsa" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10  /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /home/myuser/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110/setup; rm -rf /home/myuser/.ansible/tmp/ansible-tmp-1452847308.18-48037085136110/ >/dev/null 2>&1'

ok: [myuser@ipaddress]

TASK: [ensure tree is absent] *************************************************
<myuser@ipaddress> ESTABLISH CONNECTION FOR USER: myuser
<myuser@ipaddress> REMOTE_MODULE yum name=tree state=absent
<myuser@ipaddress> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/myuser/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/home/myuser/.ssh/id_rsa" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10  /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308 && echo $HOME/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308'
<myuser@ipaddress> PUT /tmp/tmpXyPW7R TO /home/myuser/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308/yum
<myuser@ipaddress> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/myuser/.ansible/cp/ansible-ssh-%h-%p-%r" -o IdentityFile="/home/myuser/.ssh/id_rsa" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10  /bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python -tt /home/myuser/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308/yum; rm -rf /home/myuser/.ansible/tmp/ansible-tmp-1452847335.31-110782753766308/ >/dev/null 2>&1'

failed: [myuser@ipaddress] => {"changed": false, "failed": true, "rc": 1, "results": ["Loaded plugins: fastestmirror\n"]}

msg: You need to be root to perform this command.


FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/myuser/webservers_absent.retry

myuser@ipaddress          : ok=1    changed=0    unreachable=0    failed=1 






myuser and ipaddress are redacted
Regards
Paul

Brian Coca

unread,
Jan 15, 2016, 10:04:35 AM1/15/16
to Ansible Project
how are you telling it to prompt for passwords? where are you setting
it to use sudo?
note that prompting for sudo password does NOT imply sudo will be used.


--
Brian Coca

SFT-

unread,
Jan 16, 2016, 8:25:30 AM1/16/16
to Ansible Project
Run with -K option as per man page. This will prompt you for sudo password.

Alex Leonhardt

unread,
Jan 16, 2016, 9:38:13 AM1/16/16
to ansible...@googlegroups.com
you probably want "sudo: yes" above the tasks .. ? 

Alex

On 16 January 2016 at 13:25, SFT- <ste...@gmail.com> wrote:
Run with -K option as per man page. This will prompt you for sudo password.
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

gpg public key: http://dpaste.com/1CEJ38Z 

Paul Davies

unread,
Jan 19, 2016, 8:19:03 AM1/19/16
to Ansible Project
Hi - this resolved it and makes sense but I don't understand why I didn't need this line in my install script

It was only a demo so I won't be spending any more time on it

thanks all

jaya chakravarthy

unread,
May 26, 2016, 12:24:12 PM5/26/16
to Ansible Project
You are awesome ! After about half a day of search this one solved it !

Vamsee Chowdary

unread,
Jul 8, 2018, 4:00:11 AM7/8/18
to Ansible Project
Hi paul - What is the solution ? 

Paul Davies

unread,
Jul 8, 2018, 3:10:06 PM7/8/18
to ansible...@googlegroups.com
As per previous post

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/0apDvbvRICg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

mukesh thakur

unread,
Sep 19, 2021, 8:11:39 AM9/19/21
to Ansible Project
Enable below parameters in  ansible.cfg and then try

vi /etc/ansible/ansible.cfg

 [defaults]
 inventory=hosts(file)
 [privilege_escalation]
  become=True
  become_method=sudo
  become_user=root
  become_ask_pass=False

Reply all
Reply to author
Forward
0 new messages