# why i cannot remove this file /etc/yum.repos.d/redhat-rhui,repo even with the root permission.

**URL:** <https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738>\
**Category:** Ansible Developer\
**Tags:** aws\
**Created:** [February 22, 2019, 2:08am UTC](https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738 "2019-02-22T02:08:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Yu](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Jason\_Yu](https://forum.ansible.com/u/Jason_Yu)\
**Post date:** [February 22, 2019, 2:08am UTC](https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738/1 "2019-02-22T02:08:05Z")

</div>

I got the following error when I tried to remove the /etc/yum.repos.d/redhat-rhui.repo file. My playbook is as following:

- name: Configure BASE Linux Servers  
hosts: linux  
gather\_facts: true  
become: yes  
become\_user: root  
pre\_tasks:
- name: Debug  
raw: sleep 1
- name: get the username running the deploy  
become: false  
local\_action: command whoami  
register: username\_on\_the\_host
- debug: var=username\_on\_the\_host
- name: Remove AWS RHUI  
file:  
path: “{{ item }}”  
state: absent  
force: yes  
with\_items:
- /etc/yum.repos.d/redhat-rhui.repo

roles:

- { role: linux\_common, tags: linux\_common }
- { role: deep\_security\_agent, tags: deep\_security\_agent }

\*\*\*\*\*\*\*\*\*output with error \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
amazon-ebs: changed: [default]  
amazon-ebs:  
amazon-ebs: TASK [get the username running the deploy] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*  
amazon-ebs: changed: [default → localhost]  
amazon-ebs:  
amazon-ebs: TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*  
amazon-ebs: ok: [default] =\> {  
amazon-ebs: “username\_on\_the\_host”: {  
amazon-ebs: “changed”: true,  
amazon-ebs: “cmd”: [  
amazon-ebs: “whoami”  
amazon-ebs: ],  
amazon-ebs: “delta”: “0:00:01.747620”,  
amazon-ebs: “end”: “2019-02-22 02:03:25.776013”,  
amazon-ebs: “failed”: false,  
amazon-ebs: “rc”: 0,  
amazon-ebs: “start”: “2019-02-22 02:03:24.028393”,  
amazon-ebs: “stderr”: “”,  
amazon-ebs: “stderr\_lines”: ,  
amazon-ebs: “stdout”: “root”,  
amazon-ebs: “stdout\_lines”: [  
amazon-ebs: “root”  
amazon-ebs: ]  
amazon-ebs: }  
amazon-ebs: }  
amazon-ebs:  
amazon-ebs: TASK [Remove AWS RHUI] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*  
amazon-ebs: failed: [default] (item=/etc/yum.repos.d/redhat-rhui.repo) =\> {"changed ": false, “gid”: 0, “group”: “root”, “item”: “/etc/yum.repos.d/redhat-rhui.repo”, "mode ": “0644”, “msg”: "unlinking failed: [Errno 13] Permission denied: ‘/etc/yum.repos.d/re dhat-rhui.repo’ ", “owner”: “root”, “path”: “/etc/yum.repos.d/redhat-rhui.repo”, “secon text”: “system\_u:object\_r:system\_conf\_t:s0”, “size”: 8679, “state”: “file”, “uid”: 0}  
amazon-ebs: to retry, use: --limit @/workdir/Ansible/playbooks/common/Confi gure\_Base\_Linux.retry  
amazon-ebs:  
amazon-ebs: PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*  
amazon-ebs: default : ok=4 changed=2 unreachable=0 fail ed=1  
amazon-ebs:  
==\> amazon-ebs: Terminating the source AWS instance…  
==\> amazon-ebs: Cleaning up any extra volumes…  
==\> amazon-ebs: No volumes to clean up, skipping  
==\> amazon-ebs: Deleting temporary security group…  
==\> amazon-ebs: Deleting temporary keypair…  
Build ‘amazon-ebs’ errored: Error executing Ansible: Non-zero exit status: exit status 2

==\> Some builds didn’t complete successfully and had errors:  
 → amazon-ebs: Error executing Ansible: Non-zero exit status: exit status 2

==\> Builds finished but no artifacts were created.

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [February 22, 2019, 4:09am UTC](https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738/2 "2019-02-22T04:09:35Z")

</div>

Just a guess, but is the file immutable?

Try deleting after 'chattr -i etc/yum.repos.d/redhat-rhui.repo'

Can you delete by hand on the command line?

In any case, this is a better question for the ansible-project mailing list.

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![Jason\_Yu](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Jason\_Yu](https://forum.ansible.com/u/Jason_Yu)\
**Post date:** [February 22, 2019, 10:47pm UTC](https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738/3 "2019-02-22T22:47:03Z")

</div>

Thank you for your help, it still didn’t work. In fact, I changed the module to cat a file /etc/sshd/sshd.conf but I got the same permission error:

amazon-ebs: TASK [Show /etc/ssh/sshd\_config file content] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
amazon-ebs: fatal: [default]: FAILED! =\> {“changed”: true, “cmd”: [“/bin/cat”, “/etc/ssh/sshd\_config”], “delta”: “0:00:00.005604”, “end”: “2019-02-22 22:43:50.264420”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2019-02-22 22:43:50.258816”, “stderr”: “/bin/cat: /etc/ssh/sshd\_config: Permission denied”, “stderr\_lines”: [“/bin/cat: /etc/ssh/sshd\_config: Permission denied”], “stdout”: “”, “stdout\_lines”: }  
amazon-ebs: to retry, use: --limit @/workdir/Ansible/playbooks/common/Configure\_Base\_Linux.retry

is it a “privilege escalation” error in ansible ?

---

<div class="post-metadata">

**Author:** ![Jason\_Yu](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Jason\_Yu](https://forum.ansible.com/u/Jason_Yu)\
**Post date:** [February 22, 2019, 10:48pm UTC](https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738/4 "2019-02-22T22:48:23Z")

</div>

The Configure\_Base\_Linux.yml file is as following:

- name: Configure BASE Linux Servers  
hosts: linux  
gather\_facts: true  
become: yes  
become\_user: root  
pre\_tasks:

- name: Debug  
raw: sleep 1

- name: get the username running the deploy  
become: false  
local\_action: command whoami  
register: username\_on\_the\_host

- debug: var=username\_on\_the\_host

- name: Show /etc/ssh/sshd\_config file content  
command: /bin/cat /etc/ssh/sshd\_config  
register: cat  
become: yes  
become\_method: su  
become\_user: root

- debug: var=cat.stdout\_lines

---

<div class="post-metadata">

**Author:** ![Jason\_Yu](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Jason\_Yu](https://forum.ansible.com/u/Jason_Yu)\
**Post date:** [February 22, 2019, 10:49pm UTC](https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738/5 "2019-02-22T22:49:52Z")

</div>

The part in the script befor “name: Show /etc/ssh/sshd\_config file content” works well, however, when it trys to cat the /etc/ssh/sshd\_config file, it failed and complains ““stderr\_lines”: [”/bin/cat: /etc/ssh/sshd\_config: Permission denied"]" Any gurus here can help me with this?

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [February 22, 2019, 10:54pm UTC](https://forum.ansible.com/t/why-i-cannot-remove-this-file-etc-yum-repos-d-redhat-rhui-repo-even-with-the-root-permission/29738/6 "2019-02-22T22:54:27Z")

</div>

Try the ansible-project list. This one is for development. Ask your question there and include output from running your command with '-vvv'

V/r,  
James Cassell
