# chown failed in file module

**URL:** <https://forum.ansible.com/t/chown-failed-in-file-module/16393>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [October 1, 2014, 11:36am UTC](https://forum.ansible.com/t/chown-failed-in-file-module/16393 "2014-10-01T11:36:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Subramanian\_Olagappa](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Subramanian\_Olagappa](https://forum.ansible.com/u/Subramanian_Olagappa)\
**Post date:** [October 1, 2014, 11:36am UTC](https://forum.ansible.com/t/chown-failed-in-file-module/16393/1 "2014-10-01T11:36:16Z")

</div>

Hi,

I am using ansible 1.7.2 and see the chown is not working

olga@ubuntu:~/ansible/try/02$ ansible localhost -u root -k -m file -a ‘path=/tmp/test6 state=directory mode=0700 owner=root’  
SSH password:  
localhost | FAILED \>\> {  
“failed”: true,  
“gid”: 1001,  
“group”: “olga”,  
“mode”: “0775”,  
“msg”: “chown failed”,  
“owner”: “olga”,  
“path”: “//tmp/test6”,  
“size”: 4096,  
“state”: “directory”,  
“uid”: 1001  
}

What is the right command option to create dir owned by the sudo user ?

Thanks,  
olga

---

<div class="post-metadata">

**Author:** ![Mark3](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@Mark3](https://forum.ansible.com/u/Mark3)\
**Post date:** [October 1, 2014, 11:40am UTC](https://forum.ansible.com/t/chown-failed-in-file-module/16393/2 "2014-10-01T11:40:51Z")

</div>

You are SSHing as root, is permitremoterootlogin enabled?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 1, 2014, 12:21pm UTC](https://forum.ansible.com/t/chown-failed-in-file-module/16393/3 "2014-10-01T12:21:08Z")

</div>

“You are SSHing as root, is permitremoterootlogin enabled?”

If that were the case the error would appear further up.

Also sudo isn’t being used because of the “-u root”

Is there anything unusual about /tmp we might need to know?

---

<div class="post-metadata">

**Author:** ![Mark3](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@Mark3](https://forum.ansible.com/u/Mark3)\
**Post date:** [October 2, 2014, 7:16am UTC](https://forum.ansible.com/t/chown-failed-in-file-module/16393/4 "2014-10-02T07:16:30Z")

</div>

So doing this on a bare install of ubuntu 14.04 LTS makes it work.

`

mark@ans:~$ ansible localhost -u root -k -m file -a ‘path=/tmp/test6 state=directory mode=0700 owner=root’  
SSH password:  
sudo password [defaults to SSH password]:  
localhost | success \>\> {  
“changed”: false,  
“gid”: 0,  
“group”: “root”,  
“mode”: “0700”,  
“owner”: “root”,  
“path”: “/tmp/test6”,  
“size”: 4096,  
“state”: “directory”,  
“uid”: 0  
}

`

Doing this on my CentOS will fail in the same way you see it fail.

`

[markh@sen-ansible-int ~]$ ansible localhost -u root -k -m file -a 'path=/tmp/test6 state=direct SSH password:  
sudo password [defaults to SSH password]:  
localhost | FAILED \>\> {  
“failed”: true,  
“gid”: 60007,  
“group”: “senuser”,  
“mode”: “0755”,  
“msg”: “chown failed”,  
“owner”: “markh”,  
“path”: “//tmp/test6”,  
“size”: 4096,  
“state”: “directory”,  
“uid”: 60018

`

Ofcourse there are a lot of settings that diff between these 2 systems, but one is not, and those are the filerights on /tmp which are exactly the same…

does running it in -vvvv gives you any more details?

---

<div class="post-metadata">

**Author:** ![Subramanian\_Olagappa](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Subramanian\_Olagappa](https://forum.ansible.com/u/Subramanian_Olagappa)\
**Post date:** [October 2, 2014, 11:13am UTC](https://forum.ansible.com/t/chown-failed-in-file-module/16393/5 "2014-10-02T11:13:36Z")

</div>

Hi Mark,

I’m using ubuntu 12.04 LTS and I can ssh as “root” in localhost and enabled PermitRootLogin in ssh\_config file

olga@ubuntu:~/ansible/try/02$ ansible localhost -u root -k -m file -a ‘path=/tmp/test11 state=directory mode=0700 owner=root’ -vvv  
SSH password:  
 REMOTE\_MODULE file path=/tmp/test11 state=directory mode=0700 owner=root  
 EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1412246841.03-7250721660070 && echo $HOME/.ansible/tmp/ansible-tmp-1412246841.03-7250721660070’]  
 PUT /tmp/tmptdYxcv TO /home/olga/.ansible/tmp/ansible-tmp-1412246841.03-7250721660070/file  
 EXEC [‘/bin/sh’, ‘-c’, u’LANG=C LC\_CTYPE=C /usr/bin/python /home/olga/.ansible/tmp/ansible-tmp-1412246841.03-7250721660070/file; rm -rf /home/olga/.ansible/tmp/ansible-tmp-1412246841.03-7250721660070/ \>/dev/null 2\>&1’]  
localhost | FAILED \>\> {  
“failed”: true,  
“gid”: 1001,  
“group”: “olga”,  
“mode”: “0775”,  
“msg”: “chown failed”,  
“owner”: “olga”,  
“path”: “/tmp/test11”,  
“size”: 4096,  
“state”: “directory”,  
“uid”: 1001  
}

root@ubuntu:/tmp# ls -ld /tmp  
drwxrwxrwt 12 root root 4096 Oct 2 16:23 /tmp  
root@ubuntu:/tmp#

I tried with a wrong “ssh” password for root ( -k option ) , it created the dir in /tmp and the error was same. I was not expecting this and the command should not have created the dir.

Regards,  
Olga
