# File mode with SetGID bit set gets wrong permissions.

**URL:** <https://forum.ansible.com/t/file-mode-with-setgid-bit-set-gets-wrong-permissions/15905>\
**Category:** Ansible Project\
**Created:** [August 10, 2014, 5:00pm UTC](https://forum.ansible.com/t/file-mode-with-setgid-bit-set-gets-wrong-permissions/15905 "2014-08-10T17:00:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deon\_Bredenhann](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@Deon\_Bredenhann](https://forum.ansible.com/u/Deon_Bredenhann)\
**Post date:** [August 10, 2014, 5:00pm UTC](https://forum.ansible.com/t/file-mode-with-setgid-bit-set-gets-wrong-permissions/15905/1 "2014-08-10T17:00:54Z")

</div>

- name: Create test  
file:  
path: /srv/test  
state: directory  
mode: 2770  
owner: root  
group: admin

Output of -v

{“changed”: true, “gid”: 6003, “group”: “admin”, “mode”: “05322”, “owner”: “root”, “path”: “/srv/test”, “size”: 4096, “state”: “directory”, “uid”: 0}

So the mode of 2770 somehow gets converted to 05322

So any mode with SetGID, SetUID or SetSticky, gets mangled.  
Tried in 1.6 and 1.7

1770 → 03352

2770 → 05322  
4770 → 01242

I should convert the end permissions to octal and see if there is a pattern. Will do later. Just want to post this for now and see if someone knows anything about this.

Thanks  
Deon

---

<div class="post-metadata">

**Author:** ![Greg\_Andrews](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@Greg\_Andrews](https://forum.ansible.com/u/Greg_Andrews)\
**Post date:** [August 10, 2014, 10:39pm UTC](https://forum.ansible.com/t/file-mode-with-setgid-bit-set-gets-wrong-permissions/15905/2 "2014-08-10T22:39:24Z")

</div>

There’s no leading “0” on your mode number 2770. In Perl, the run-time parses numbers as decimal unless they have certain hint prefixes, like “0x” for hexadecimal and “0” for octal.

I don’t know how Python parses numbers, but 2770 decimal = 5322 octal, so it looks like that may be the source of the confusion. The [ansible.com](http://ansible.com) docs for the file module don’t address this explicitly, but both the examples have a leading “0” in the mode number. It looks to me like a mode number of “02770” is what you need.

-Greg

---

<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:** [August 11, 2014, 12:28pm UTC](https://forum.ansible.com/t/file-mode-with-setgid-bit-set-gets-wrong-permissions/15905/3 "2014-08-11T12:28:19Z")

</div>

Ansible contains some fuzzy logic for this.

Basically, if the number is a string, it will assume octal.

If you pass in a decimal, as you have done above, it will assume you know what you are doing. (Most people use short-form arguments in Ansible, here you’ve split to another line and passed a decimal - which is fine).

So yes, this would be it.

Alternatively, this would also fit:

mode: “777”

---

<div class="post-metadata">

**Author:** ![Deon\_Bredenhann](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@Deon\_Bredenhann](https://forum.ansible.com/u/Deon_Bredenhann)\
**Post date:** [August 12, 2014, 8:32am UTC](https://forum.ansible.com/t/file-mode-with-setgid-bit-set-gets-wrong-permissions/15905/4 "2014-08-12T08:32:14Z")

</div>

Thank you Greg and Michael.

That was the whole solution to the problem.
