New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4-digit octal mode works incorrectly unless quoted #9196

Closed
saizai opened this Issue Sep 29, 2014 · 8 comments

Comments

Projects
None yet
8 participants
@saizai
Copy link

saizai commented Sep 29, 2014

Example:

    - name: Secure home directory
      file:
        path: "/home/{{ lookup('env', 'USER') }}/"
        state: touch
        owner: "{{lookup('env', 'USER') }}"
        group: "{{lookup('env', 'USER') }}"
        mode: '2750' 

If it's 2750 (without quotes), the resulting directory has permissions d-wSrwxrwT.

If it's '2750' (with quotes), the resulting directory has permissions drwxr-s--- (correct).

@ansibot

This comment has been minimized.

Copy link
Contributor

ansibot commented Sep 29, 2014

Can You Help Us Out?

Thanks for filing a ticket! I am the friendly GitHub Ansibot.

It looks like you might not have filled out the issue description based on our standard issue template. You might not have known about that, and that's ok too, we'll tell you how to do it.

We have a standard template because Ansible is a really busy project and it helps to have some standard information in each ticket, and GitHub doesn't yet provide a standard facility to do this like some other bug trackers. We hope you understand as this is really valuable to us!.

Solving this is simple: please copy the contents of this template and paste it into the description of your ticket. That's it!

If You Had A Question To Ask Instead

If you happened to have a "how do I do this in Ansible" type of question, that's probably more of a user-list question than a bug report, and you should probably ask this question on the project mailing list instead.

However, if you think you have a bug, the report is the way to go! We definitely want all the bugs filed :) Just trying to help!

About Priority Tags

Since you're here, we'll also share some useful information at this time.

In general tickets will be assigned a priority between P1 (highest) and P5, and then worked in priority order. We may also have some follow up questions along the way, so keeping up with follow up comments via GitHub notifications is a good idea.

Due to large interest in Ansible, humans may not comment on your ticket immediately.

Mailing Lists

If you have concerns or questions, you're welcome to stop by the ansible-project or ansible-development mailing lists, as appropriate. Here are the links:

Thanks again for the interest in Ansible!

@mpdehaan

This comment has been minimized.

Copy link
Contributor

mpdehaan commented Sep 29, 2014

Hi!

Thanks very much for your submission to Ansible. It sincerely means a lot to us.

We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated.

In particular, we believe you have said:

  • the octal mode doesn't work right if not quoted

However, however what is happening is that:

  • if not quoted, the value being specified is decimal, not octal
  • an octal value is not being passed to the module but a pure number

We would suggest:

  • always quoting the value or specifiying the value as an octal number by using a leading zero
  • OR using the string format one-liner version of ansible module invocations, common throughout the docs, which pass strings

In the future, this might be a topic more well suited for the user list, which you can also post here if you'd like some more help with the above.

Thank you once again for this and your interest in Ansible!

@mpdehaan mpdehaan closed this Sep 29, 2014

@saizai

This comment has been minimized.

Copy link

saizai commented Sep 29, 2014

@mpdehaan What I meant is octal in the sense of chmod — not as in a Ruby octal number.

What possible (intended) interpretation of "mode: 2750" do you think there is that makes the result be d-wSrwxrwT?

AFAICT, the only interpretation is the same as chmod 2750 …, and therefore Ansible should interpret it that way.

@sivel

This comment has been minimized.

Copy link
Member

sivel commented Sep 29, 2014

I believe the confusion is coming from the way that python and yaml (pyyaml) work with each other in regards to octal values.

When you specify mode: 2750 you are indicating that you are giving it a decimal value, and not octal. When the value is a string, the logic in python interprets it as octal. Such a representation would look like mode: "2750". The octal equivalent of 2750 (decimal) is 05276, which is effectively what you speciefied. Python 2.x denotes octal values using a preceding 0.

Your options would be something such as:

As a string:

mode: "2750"

Using proper python 2.x octal notation:

mode: 02750

Using a decimal representation of octal mode 02750:

mode: 1512
@vmindru

This comment has been minimized.

Copy link
Contributor

vmindru commented Nov 4, 2016

this has to be somehow fixed, enforcing one to use any of the above methods is not cool or this has to be explicitly mentioned in the docs. right now the docs are ambiguous asking one to use a leading 0 ....

@mrwacky42

This comment has been minimized.

Copy link
Contributor

mrwacky42 commented Nov 10, 2016

Agreed, the docs are infuriatingly vague.
This seems to work as expected:

- name: Create stick directory
  file:
    path=/tmp/sticky
    state=directory
    mode=1777
    owner=root
    group=root
@dgeo

This comment has been minimized.

Copy link
Contributor

dgeo commented Jan 19, 2017

I understand the problem, but I also think it could be better documented

In my case I read on this page: http://docs.ansible.com/ansible/file_module.html

# change file ownership, group and mode. When specifying mode using octal numbers, first digit should always be 0.
- file:
    path: /etc/foo.conf
    owner: foo
    group: foo
    mode: 0644

Of course, as many, I was looking for a syntax example, my eyes caught 0664 and I though the above statement was for people with less unix-perms knowledge (now I know I shouldn't have)
I've used mode: NNNN some time before getting my big mistake...

I'd have been helped here with examples quoted.
(and a copy of @sivel 's explanation in the above doc would be perfect for me :)

@samuelharmer

This comment has been minimized.

Copy link

samuelharmer commented Aug 19, 2018

For future visitors, you may use the notation mode: 0o600 or umask: 0o077.

lousyd added a commit to lousyd/ansible that referenced this issue Aug 20, 2018

Clarify docs re mode's octal representation
I changed the language about how to use mode, calling attention to the
fact that one is *adding* a zero to mark it as octal to Python, rather
than simply including the zero that one might have put there when using
the chmod command on a Unix command line. This makes it more obvious
that using "01777" is not a typo, because the leading zero is not meant
to reflect the way that number might have been given on a command line.

As pointed out in PEP 3127, "The default octal representation of
integers is silently confusing to people unfamiliar with C-like
languages." That PEP is standards track with final status.

See also: issues ansible#5409 ansible#9196 ansible#11385 ansible#13115 ansible#18952 ansible#23491 ansible#23521

acozine added a commit that referenced this issue Aug 29, 2018

Clarify docs re mode's octal representation (#44410)
* Clarify docs re mode's octal representation

I changed the language about how to use mode to make it more obvious
that using "01777" is not a typo, because the leading zero is not meant
to reflect the way that number might have been given on a command line.
See also: issues #5409 #9196 #11385 #13115 #18952 #23491 #23521

Tomorrow9 added a commit to Tomorrow9/ansible that referenced this issue Nov 20, 2018

Clarify docs re mode's octal representation (ansible#44410)
* Clarify docs re mode's octal representation

I changed the language about how to use mode to make it more obvious
that using "01777" is not a typo, because the leading zero is not meant
to reflect the way that number might have been given on a command line.
See also: issues ansible#5409 ansible#9196 ansible#11385 ansible#13115 ansible#18952 ansible#23491 ansible#23521
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment