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

**URL:** <https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215>\
**Category:** Ansible Project\
**Created:** [January 14, 2016, 4:31pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215 "2016-01-14T16:31:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Davies](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@Paul\_Davies](https://forum.ansible.com/u/Paul_Davies)\
**Post date:** [January 14, 2016, 4:31pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/1 "2016-01-14T16:31:26Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Paul\_Davies](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@Paul\_Davies](https://forum.ansible.com/u/Paul_Davies)\
**Post date:** [January 14, 2016, 4:32pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/2 "2016-01-14T16:32:22Z")

</div>

I should add that this is Ansible 1.9.4

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 14, 2016, 5:13pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/3 "2016-01-14T17:13:39Z")

</div>

can you run both with -vvvv to see what Ansible is doing? also show  
the command line invocation of both playbooks.

---

<div class="post-metadata">

**Author:** ![Paul\_Davies](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@Paul\_Davies](https://forum.ansible.com/u/Paul_Davies)\
**Post date:** [January 15, 2016, 8:52am UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/4 "2016-01-15T08:52:00Z")

</div>

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](mailto: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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 15, 2016, 3:04pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/5 "2016-01-15T15:04:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SFT](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@SFT](https://forum.ansible.com/u/SFT)\
**Post date:** [January 16, 2016, 1:25pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/6 "2016-01-16T13:25:29Z")

</div>

Run with -K option as per man page. This will prompt you for sudo password.

---

<div class="post-metadata">

**Author:** ![Alex\_Leonhardt](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Alex\_Leonhardt](https://forum.ansible.com/u/Alex_Leonhardt)\
**Post date:** [January 16, 2016, 2:38pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/7 "2016-01-16T14:38:03Z")

</div>

you probably want “sudo: yes” above the tasks … ?

Alex

---

<div class="post-metadata">

**Author:** ![Paul\_Davies](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@Paul\_Davies](https://forum.ansible.com/u/Paul_Davies)\
**Post date:** [January 19, 2016, 1:19pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/8 "2016-01-19T13:19:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jaya\_chakravarthy](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jaya\_chakravarthy](https://forum.ansible.com/u/jaya_chakravarthy)\
**Post date:** [May 26, 2016, 11:36am UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/9 "2016-05-26T11:36:53Z")

</div>

You are awesome ! After about half a day of search this one solved it !

---

<div class="post-metadata">

**Author:** ![Vamsee\_Chowdary](https://avatars.discourse-cdn.com/v4/letter/v/eb8c5e/32.png) [@Vamsee\_Chowdary](https://forum.ansible.com/u/Vamsee_Chowdary)\
**Post date:** [July 8, 2018, 8:00am UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/10 "2018-07-08T08:00:11Z")

</div>

Hi paul - What is the solution ?

---

<div class="post-metadata">

**Author:** ![Paul\_Davies](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@Paul\_Davies](https://forum.ansible.com/u/Paul_Davies)\
**Post date:** [July 8, 2018, 7:09pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/11 "2018-07-08T19:09:42Z")

</div>

As per previous post

---

<div class="post-metadata">

**Author:** ![mukesh\_thakur](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@mukesh\_thakur](https://forum.ansible.com/u/mukesh_thakur)\
**Post date:** [September 19, 2021, 12:11pm UTC](https://forum.ansible.com/t/yum-state-absent-leads-to-you-need-to-be-root-to-perform-this-command/20215/12 "2021-09-19T12:11:39Z")

</div>

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
