使用ansible playbook将文件从本地复制到远程时如何保留文件的mtime/ctime?

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

我正在尝试将脚本复制到远程计算机,我必须保留文件的 mtime

我已尝试使用 mode:preservemode=preserve,如 ansible 文档中所述,here! 但它似乎只保留权限和所有权。

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

关于您的问题和 Zeitounator, I've setup a test with synchronize_module and with parameter times 的评论,它按要求工作。

---
- 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

感谢