This one fooled me for a little while because I wasn’t paying attention (Ansible 1.6.6).
I ran
% ansible machine -m file -a ‘path=/tmp/jon state=touch mode=0644 owner=root’
The file ‘/tmp/jon’ was created, but Ansible returned
ansible | FAILED >> {
“failed”: true,
“gid”: 1000,
“group”: “jonf”,
“mode”: “0664”,
“msg”: “chown failed”,
“owner”: “jonf”,
“path”: “/tmp/jon”,
“size”: 0,
“state”: “file”,
“uid”: 1000
}
The “FAILED” fooled me, since the file was created. Then I noticed the “chown failed” message. This was caused by the fact that the remote user isn’t root so it can’t change owner.
I was hoping that a simple command like this would either completely succeed or completely fail. If it fails, it shouldn’t change the state of the system it’s running on. Instead, it leaves ‘/tmp/jon’ in place, but it isn’t owned by the specified user.
One could argue that the file module should fail without doing anything if it’s told to change ownership of a file, and the module isn’t being run as root.
Jon
Hi,
Please make sure you are on the most recent version of Ansible if asking questions to this list. Many things have changed or been improved in various releases, and it’s quick to upgrade.
The current latest version is 1.7.1.
I believe the chown attempts as non-root has already been addressed.
Hi,
Please make sure you are on the most recent version of Ansible if asking questions to this list. Many things have changed or been improved in various releases, and it’s quick to upgrade.
The current latest version is 1.7.1.
This is excellent advice. You’re absolutely right. I just upgraded.
I believe the chown attempts as non-root has already been addressed.
It doesn’t look this way. This is on a host where /etc/ansible/hosts contains
[all]
localhost
$ ls -l /tmp/jon
ls: cannot access /tmp/jon: No such file or directory
$ ansible --version
ansible 1.7.1
$ ansible all -m file -a ‘path=/tmp/jon state=touch mode=0644 owner=root’
localhost | FAILED >> {
“failed”: true,
“gid”: 1000,
“group”: “jonf”,
“mode”: “0664”,
“msg”: “chown failed”,
“owner”: “jonf”,
“path”: “/tmp/jon”,
“size”: 0,
“state”: “file”,
“uid”: 1000
}
$ ls -l /tmp/jon
-rw-rw-r-- 1 jonf jonf 0 Aug 27 18:07 /tmp/jon
This is the same behavior as with 1.6.6. After Ansible runs ‘/tmp/jon’ exists with the wrong owner.
Don’t you think it should exist with the correct owner or it shouldn’t exist at all?
Jon
Sorry, perhaps addressed on devel only. I hate to be that annoying, but it would save me time if you could let me know if you see the same there.
I do know we handled chown specifically around something like this, though it might have been specific to atomic_move.
If it’s still in devel, definitely file a bug.
Thanks!
Still there. I'll file a bug.
% bin/ansible --version
ansible 1.8 (devel a0635ebb0d) last updated 2014/09/01 16:52:36 (GMT -700)
% bin/ansible all -m file -a 'path=/tmp/jon state=touch mode=0644 owner=root'
localhost | FAILED >> {
"failed": true,
"gid": 1000,
"group": "jonf",
"mode": "0664",
"msg": "chown failed",
"owner": "jonf",
"path": "/tmp/jon",
"size": 0,
"state": "file",
"uid": 1000
}
% ls -l /tmp/jon
-rw-rw-r-- 1 jonf jonf 0 Sep 1 16:54 /tmp/jon
Jon