Couple things: I've tested this a few times and I just want to be
clear that you're seeing what I am:
Octal works fine: ie:
file:
path: /var/tmp/test
mode: 0644
Strings also work fine:
file:
path: /var/tmp/test
mode: "644"
Decimal integers that look like the octal modes do not work fine:
file:
path: /var/tmp/test
mode: 644
I faced the issue with the following organization:
# roles/common/vars/main.yml
my_dirs:
- path: /path/to/dir
owner: user
group: group
mode: 0775
# roles/common/tasks/main.yml
- name: "Create my dirs"
file:
path: "{{ item.path }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
state: directory
with_items: my_dirs
The workaround was to specify the mode between quotes in vars/main.yml.
Thinking now, the {{ }} might be unnecessary is this specific case? I
think I naturally defaulted to quote everything in in my tasks but might
not be the right thing to do here.
Is it right to assume the playbooks are processed in the following way?
[text files] -> [jinja] -> [ansible runner]
Now my thoughts: I don't think we can do more processing without
opening up different cornercases. Both the octal specification and
the decimal specification are numbers. That means that by the time
the module gets a hold of the value it no longer knows whether the
user specified the number as base 10 or base 8. It's simply an int.
This makes any preprocessing we'd do ambiguous. For instance, let's
say the file module gets a mode parameter of 420. If we're going to
try to second guess the user we end up having to ask the question is
that -r---w---- (user specified 420 and meant 0420) or is it
-rw-r--r-- (user specified 0644 and meant 0644) with no way to tell
for sure which is which.
Yeah, this makes sense.
If we didn't care about backwards compatibility we could tell ansible
that the value of mode must be a string. Then we could make sure that
we parsed the string as an octal value always. However, that seems
like a somewhat high price to pay here since most greybeards
understand that this is an octal value and needs to be prepended with
a zero in most programming contexts. Middle ground might be to
clarify the documentation for the mode parameter. That seems to be
the route that languages like php take:
http://php.net/manual/en/function.chmod.php
It looks like a good compromise. Are the docs generated from the
docstring in the modules or somewhere else?
Thanks,
Giovanni