question about mode=preserve with file module

62 views
Skip to first unread message

Martey Dodoo

unread,
Aug 20, 2020, 3:34:20 PM8/20/20
to Ansible Project
Hi everyone,

I'm having some issues using the "mode" parameter on the file module to change ownership of an existing directory without modifying its permissions. For example:

> - name: use preserve mode
>   file:
>     path=/tmp/test
>     owner=www-data
>     mode=preserve
>     state=directory
>   become: true

Based on the documentation, I would assume that this would "preserve" the directory's existing permissions while changing its owner. Instead, it fails with "mode must be in octal or symbolic form" / "bad symbolic permission for mode: preserve".

I've managed to get the behavior I need by using an empty string for the mode parameter, but I am unsure why "preserve" doesn't work. Is this a bug in the file module? Am I reading the documentation wrong?

Thanks,
Martey

Dick Visser

unread,
Aug 20, 2020, 3:53:04 PM8/20/20
to ansible...@googlegroups.com
Not sure it makes any difference but can you try to use the colon yaml syntax for the parameters

--


You received this message because you are subscribed to the Google Groups "Ansible Project" group.


To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/74a54f7c-bfa3-4dd4-a992-b4804ecf6e19n%40googlegroups.com.


--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Martey Dodoo

unread,
Aug 20, 2020, 4:18:20 PM8/20/20
to ansible...@googlegroups.com
Not sure it makes any difference but can you try to use the colon yaml syntax for the parameters

Using standard YAML syntax instead of key=value displays the same error message. 

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/HlF429Z0Zow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwPrUiPyk4u%2BjxQnzL40tLxkg9qWesP4Y3hcWY%2BQniJ1Fg%40mail.gmail.com.


--
Martey Dodoo
Principal Developer, Mobolic

Dick Visser

unread,
Aug 20, 2020, 11:13:07 PM8/20/20
to ansible...@googlegroups.com

Stefan Hornburg (Racke)

unread,
Aug 21, 2020, 1:37:30 AM8/21/20
to ansible...@googlegroups.com
On 8/20/20 9:34 PM, Martey Dodoo wrote:
> Hi everyone,
>
> I'm having some issues using the "mode" parameter on the file module
> <https://docs.ansible.com/ansible/latest/modules/file_module.html#parameter-mode> to change ownership of an existing
> directory without modifying its permissions. For example:
>
>> - name: use preserve mode
>>   file:
>>     path=/tmp/test
>>     owner=www-data
>>     mode=preserve
>>     state=directory
>>   become: true
>
> Based on the documentation, I would assume that this would "preserve" the directory's existing permissions while
> changing its owner. Instead, it fails with "mode must be in octal or symbolic form" / "bad symbolic permission for mode:
> preserve".
>
> I've managed to get the behavior I need by using an empty string for the mode parameter, but I am unsure why "preserve"
> doesn't work. Is this a bug in the file module? Am I reading the documentation wrong?

Hello Martey,

my reading of the documentation is that "preserve" applies only when you are using the "src" parameter. For example when
you are creating a symlink.

Regards
Racke

>
> Thanks,
> Martey
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/74a54f7c-bfa3-4dd4-a992-b4804ecf6e19n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

wne...@gmail.com

unread,
Aug 21, 2020, 10:54:29 AM8/21/20
to Ansible Project
On Thursday, August 20, 2020 at 9:34:20 PM UTC+2 Martey Dodoo wrote:
Hi everyone,

I'm having some issues using the "mode" parameter on the file module to change ownership of an existing directory without modifying its permissions. For example:

> - name: use preserve mode
>   file:
>     path=/tmp/test
>     owner=www-data
>     mode=preserve
>     state=directory
>   become: true

Based on the documentation, I would assume that this would "preserve" the directory's existing permissions while changing its owner. Instead, it fails with "mode must be in octal or symbolic form" / "bad symbolic permission for mode: preserve". 
...

have a look at this comment

according to that comment, it is not intended to work with file. 

kind regards, markus

Vladimir Botka

unread,
Aug 21, 2020, 5:15:02 PM8/21/20
to Martey Dodoo, ansible...@googlegroups.com
Martey,

On Thu, 20 Aug 2020 12:34:20 -0700 (PDT)
Martey Dodoo <mar...@mobolic.com> wrote:

> ... the "mode" parameter on the file module to change ownership of
> an existing directory without modifying its permissions. For
> example:
>
> - name: use preserve mode
> file:
> path=/tmp/test
> owner=www-data
> mode=preserve
> state=directory
> become: true

When "state=directory" the parameter mode says "The permissions the
resulting file or directory should have". There is no reason to use
"mode=preserve" if you don't want to change the mode. Simply remove
the line

- name: use preserve mode
file:
path=/tmp/test
owner=www-data
state=directory
become: true

--
Vladimir Botka
Reply all
Reply to author
Forward
0 new messages