Ansible 复制模块不保留目录的权限,而只保留文件

时间:2021-01-15 14:33:18

标签: directory ansible permissions copy backup

实际文件夹有 777 个权限,如下所示:

drwxrwxrwx 3 destuser destuser 29 Jan 14 08:40 /tmp/mohtas/folder

我使用以下剧本进行了备份,并希望保留备份文件夹的权限,即 777

---
- name: "Play 3"
  hosts: all
  user: destuser
  gather_facts: false

  tasks:

    - set_fact:
        tdate: "bkp.{{ '%d%b%Y_%H%M%S' | strftime }}"
    - name: Take Backup when dest_path and source path are the same.
      ignore_errors: yes
      copy:
        src: "/tmp/mohtas/folder"
        dest: "/tmp/mohtas/folder.{{ tdate }}"
        mode: preserve

但是,创建的备份文件夹具有不同的权限,如下所示:

drwxr-xr-x 3 destuser destuser 17 Jan 15 09:07 /tmp/mohtas/folder.bkp.15Jan2021_090700

奇怪的是,如果我提到 src: /tmp/mohtas/file.txt 作为文件而不是目录,备份权限会被保留。

我知道我可以使用 stat 模块,但我正在寻找更好/更快的解决方案,因为我正在处理文件/文件夹循环。

我的 ansible 版本是

[destuser@desthost /]$ ansible --version
ansible 2.4.2.0
  config file = /home/destuser/.ansible.cfg
  configured module search path = [u'/home/destuser/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5

0 个答案:

没有答案