bareMetal
bareMetal

Reputation: 551

How to preserve mtime/ctime of a file while copying file from local to remote using ansible playbook?

I am trying to copy a script to a remote machine and I have to preserve mtime of the file.

I have tried using mode:preserve and mode=preserve as stated in ansible documentation, here! but it seems to preserve permissions and ownership only.

- name: Transfer executable script script
  copy:
    src: /home/avinash/Downloads/freeradius.sh
    dest: /home/ssrnd09/ansible
    mode: preserve

Upvotes: 0

Views: 1480

Answers (1)

U880D
U880D

Reputation: 12145

In respect to your question and the comment of Zeitounator, I've setup a test with synchronize_module and with parameter times, which was working as required.

---
- hosts: test.example.com
  become: no
  gather_facts: no

  tasks:

  - name: Synchronize passing in extra rsync options
    synchronize:
      src: test.sh
      dest: "/home/{{ ansible_user }}/test.sh"
      times: yes

Thanks to

Upvotes: 1

Related Questions