使用 Ansible 复制模块进行远程到远程文件传输(同一远程主机)



我正在尝试使用 Ansible 的复制模块将特定远程目录下的所有文件移动到另一个远程目录 - 在同一远程主机上。

目录和文件确实存在于远程主机上,我想我会使用 Ansible 复制模块,remote_src:是的,以实现这一点。

但是,到目前为止,我在这种方法中遇到了不可预见的问题 - 任何帮助都值得赞赏,谢谢!!

关注的任务

- name: copy remote to remote (same host)
  copy:
    src: "{{ item }}"
    dest: "{{ dir_base_path }}/go/to/my/nested/path"
    remote_src: yes
    owner: "{{ owner }}"
    group: "{{ group }}"
    mode: preserve
  with_fileglob:
    - "{{ dir_base_path }}/stay/at/parent_dir/*"
  when: status.changed and dir.stat.exists

远程目录结构

--> parent path
   -- all-the-files-I-need
   --`nested_directory
      -- need-to-copy-files here

观察到的错误

TASK [playbook: copy remote to remote (same host)] ****************************************************************************************
 [WARNING]: Unable to find 'base_path/stay/at/parent_dir/' in expected paths (use -vvvvv to see paths)

版本信息

ansible --version
ansible 2.7.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]

根据 fileglob 的文档 - 匹配是针对 Ansible 控制器上的本地系统文件。要迭代远程节点上的文件列表,请使用 find 模块。参考: https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html

您可以先使用 find 命令查找文件,然后使用注册进行存储,然后复制这些文件。

最新更新