问题描述
作为用户,我想将文件从 node1 复制到 node2.是否可以使用复制模块 + delegate_to
As a user I want to copy file from node1 to node2. Is it possible with copy module + delegate_to
下面是我试图做的.Playbook 从 node3 运行.
Below is what I was trying to do. Playbook is running from node3.
Playbook Sample
---
- name: Gather Facts for all hosts
hosts: all
gather_facts: true
any_errors_fatal: true
become: true
- name: Test
hosts: all
gather_facts: false
any_errors_fatal: true
become: true
roles:
- role: test
Role Sample
---
- block:
- include_tasks: test.yml
any_errors_fatal: true
run_once: true
Task Sample
---
- name: Test
block:
- name: Transfer files from node1 to node2
copy:
src: /tmp/a
dest: /tmp/
delegate_to: node2
delegate_to: node1
推荐答案
简短的回答是否:您将无法使用 copy
模块执行此操作.
The short answer is no: you will not be able to do this with the copy
module.
然而,您可能想看看 synchronize
模块
You might however want to have a look at the synchronize
module
引用文档
可以使用 delegate_to 将本地主机"更改为不同的主机.这允许在两台远程主机之间或完全在一台远程机器上进行复制.
你基本上会得到类似的结果:
You would basically end up with something like:
---
- name: Rsync some files
hosts: my_target_host
tasks:
- name: copy my file
synchronize:
src: path/on/source/host
dest: path/on/dest/host
delegate_to: my_source_host
编辑我刚刚发现 这篇文章 引用了 synchronize
以及 fetch
/copy 方法,你可能想看看.
Edit I just found this article referencing synchronize
as well as the fetch
/copy method that you might want to look at.
这篇关于使用嵌套的 delegate_to 将文件从一台远程服务器复制到另一台远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!