File date/time stamps

11 views
Skip to first unread message

Antony Stone

unread,
Jun 17, 2022, 5:56:48 AM6/17/22
to Ansible Project
Hi.

I have a generic question about ansible, and the way it manages files on target
(managed) systems. They're all Linux systems.

I'm working in an environment where a colleague is running ansible scripts to
manage servers I work with, and I see that every time ansible runs, it updates
date and time stamps on files it is managing, even when the content is already
correct and isn't being changed.

Is this a standard feature of ansible and the way it does configuration
management, or does it suggest that there's something incorrect or at least
inefficient about the way it's being used here?

I'm really not familiar with ansible myself, but I have used puppet in the
past, and that didn't do this - if a file was already correct it did not get
touched.

Thanks for any advice.


Antony.

--
Numerous psychological studies over the years have demonstrated that the
majority of people genuinely believe they are not like the majority of people.

Please reply to the list;
please *don't* CC me.

Vladimir Botka

unread,
Jun 17, 2022, 8:24:40 AM6/17/22
to Antony Stone, ansible...@googlegroups.com
On Fri, 17 Jun 2022 10:56:13 +0100
Antony Stone <Antony...@ansible.open.source.it> wrote:

> I have a generic question about ansible, and the way it manages files on target
> (managed) systems. They're all Linux systems.
>
> I'm working in an environment where a colleague is running ansible scripts to
> manage servers I work with, and I see that every time ansible runs, it updates
> date and time stamps on files it is managing, even when the content is already
> correct and isn't being changed.
>
> Is this a standard feature of ansible and the way it does configuration
> management, or does it suggest that there's something incorrect or at least
> inefficient about the way it's being used here?

No. It's not a standard feature of Ansible. Just the opposite, in
most cases the goal is to make a playbook idempotent. There should be
no changes reported when running a playbook repeatedly.

It depends on the module and it might be configurable. For example,
the module *file* allows to preserve *access_time* and
*modification_time* because you might want to configure them depending
on your use case.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html

Try to find out which Ansible module(s) is/are causing the troubles.
The task should report 'changed: true'. For example, the task below
(running at localhost only)

- file:
state: touch
path: /tmp/test

will repeatedly report 'changed'

TASK [file] ************************************************
changed: [localhost]

The task will become idempotent when you set both *access_time* and
*modification_time* to 'preserve'

- file:
state: touch
path: /tmp/test
access_time: preserve
modification_time: preserve

To move on, it will be necessary to learn details.

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