Ansible copy不保留模式为“的原始权限”;保留;使用远程\u src时

Ansible copy不保留模式为“的原始权限”;保留;使用远程\u src时,ansible,ansible-2.x,Ansible,Ansible 2.x,我使用的是Ansible2.8.5(目标服务器是Red Hat4.8.5-39)。我正在将一些文件/目录从GitLab复制到几个远程主机中 我正在首先将初始副本复制到共享位置(因此运行一次:true): …然后将文件复制到每个主机上的所需位置: - name: "Deploy/Install new application" block: # All this Jiu Jitsu just to clear {{ path_home }}/ directory - name:

我使用的是Ansible
2.8.5
(目标服务器是Red Hat
4.8.5-39
)。我正在将一些文件/目录从GitLab复制到几个远程主机中

我正在首先将初始副本复制到共享位置(因此
运行一次:true
):

…然后将文件复制到每个主机上的所需位置:

- name: "Deploy/Install new application"
  block:
    # All this Jiu Jitsu just to clear {{ path_home }}/ directory
    - name: "Collecting current directories and/or files inside {{ path_home }}/"
      find:
        file_type: any
        hidden: yes
        paths: "{{ path_home }}/"
      register: collected_items
    - name: "Removing current directories and/or files inside {{ path_home }}/"
      file:
        path: "{{ item.path }}"
        state: absent
      with_items: "{{ collected_items.files }}"
    - name: "Copying new application, configuration, and support files"
      copy:
        dest: "{{ path_home }}/"
        mode: preserve
        remote_src: yes
        src: "{{ path_tmp }}/{{ CI_PIPELINE_ID }}/"
    ...
问题是文件权限没有得到“尊重”,我不想定义几个步骤来纠正这一点。这就是最初复制文件/目录的方式(以及我希望它们的方式):

[deployer@unix核心]$ll-AR 41397/
41397/:
总数5100万
drwxr-xr-x。3雄猫4.0K 10月11日11:23。
drwxr-xr-x。5 tomcat 4.0K 10月11日11:22。。
drwxr-xr-x。2 tomcat 4.0K 10月11日11:23配置
-rw-r--r--。1 tomcat 1.2K 10月11日11:23 core.conf
-rwxr-xr-x。1 tomcat 50米10月11日11:23 core.war
41397/配置:
总数12千
drwxr-xr-x。2 tomcat 4.0K 10月11日11:23。
drwxr-xr-x。3 tomcat 4.0K 10月11日11:23。。
-rw-r--r--。1 tomcat 1.6K 10月11日11:23 logback.xml
…这就是使用
remote\u src:yes
复制后的外观:

[deployer@unixcore]$ll-AR/data/st01/apps/core/
/data/st01/apps/core/:
总共50米
drwxr-xr-x。3雄猫4.0K 10月11日11:23。
drwxr-xr-x。3雄猫4.0K 10月9日16:36。。
drwxr-xr-x。2 tomcat 4.0K 10月11日11:23配置
-rw-r-----。1 tomcat 1.2K 10月11日11:23 core.conf
-rw-r-----。1 tomcat 50米10月11日11:23 core.war
/data/st01/apps/core/config:
总数12千
drwxr-xr-x。2 tomcat 4.0K 10月11日11:23。
drwxr-xr-x。3 tomcat 4.0K 10月11日11:23。。
-rw-r--r--。1 tomcat 1.6K 10月11日11:23 logback.xml
是否可以使用
远程\u src:yes
并保留原始文件/目录权限?的文档说明了这一点,但我可能遗漏了一些内容。

ansible文档说明

远程\u src支持从版本开始的递归复制。 remote_src仅适用于mode=preserve as of version

您需要将系统降级到ansible 2.6,或者尝试使用所需权限(如0644或01777)为“模式”提供权限

远程\u src支持从版本开始的递归复制。 remote_src仅适用于mode=preserve as of version


您需要将系统降级为ansible 2.6,或者尝试为“模式”提供所需的权限(如0644或01777)

我的另一个解决方案是使用
同步
模块,因为我没有太多的文件要复制/移动:

-name:“复制最新的应用程序生成、配置和支持文件”
使同步:
删除:是
dest:{{app_path}}/latest/“
递归:是的
src:{{tmp_path}}/{{PIPELINE_ID}}}/“
委托给:“{{inventory\u hostname}”

我的另一个解决方案是使用
同步
模块,因为我没有很多文件要复制/移动:

-name:“复制最新的应用程序生成、配置和支持文件”
使同步:
删除:是
dest:{{app_path}}/latest/“
递归:是的
src:{{tmp_path}}/{{PIPELINE_ID}}}/“
委托给:“{{inventory\u hostname}”

我明白了,但我会假设不管怎样,如果我指定
模式:保留
它都会遵守该设置,对吗?我明白了,但我会假设不管怎样,如果我指定
模式:保留
它都会遵守该设置,对吗?你找到解决方案了吗?我今天在Ansible 2.9.6上遇到了这种情况(远程源代码,目录的递归副本,mode=preserve-specified),但是使用重置权限获取文件(当然被umask屏蔽)。因为我没有太多的文件,所以我使用了
synchronize
模块。实际上,我在目录中只有一个文件,因此,最终将该文件复制到一个目录目标——如果该目录不存在,则生成该目录。并且权限被正确保留。您是否找到解决方案?我今天在Ansible 2.9.6上遇到了这种情况(远程源代码,目录的递归副本,mode=preserve-specified),但是使用重置权限获取文件(当然被umask屏蔽)。因为我没有太多的文件,所以我使用了
synchronize
模块。实际上,我在目录中只有一个文件,因此,最终将该文件复制到一个目录目标——如果该目录不存在,则生成该目录。并且正确地保留了权限。
- name: "Deploy/Install new application"
  block:
    # All this Jiu Jitsu just to clear {{ path_home }}/ directory
    - name: "Collecting current directories and/or files inside {{ path_home }}/"
      find:
        file_type: any
        hidden: yes
        paths: "{{ path_home }}/"
      register: collected_items
    - name: "Removing current directories and/or files inside {{ path_home }}/"
      file:
        path: "{{ item.path }}"
        state: absent
      with_items: "{{ collected_items.files }}"
    - name: "Copying new application, configuration, and support files"
      copy:
        dest: "{{ path_home }}/"
        mode: preserve
        remote_src: yes
        src: "{{ path_tmp }}/{{ CI_PIPELINE_ID }}/"
    ...