Ansible 使用嵌套的委托\u将文件从一个远程服务器复制到另一个远程服务器
作为用户,我想将文件从node1复制到node2。是否可以通过复制模块+委托给 下面是我想做的。Playbook正在从节点3运行Ansible 使用嵌套的委托\u将文件从一个远程服务器复制到另一个远程服务器,ansible,Ansible,作为用户,我想将文件从node1复制到node2。是否可以通过复制模块+委托给 下面是我想做的。Playbook正在从节点3运行 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_
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
简短的回答是“否”:您将无法使用复制模块执行此操作
不过,您可能想看看
引用文件
“本地主机”可以通过使用委托更改为其他主机。这允许在两个远程主机之间或完全在一台远程计算机上进行复制
你基本上会得到这样的结果:
---
- 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
编辑我刚刚找到引用同步以及您可能想要查看的/copy方法。简短的回答是否:您将无法使用复制模块执行此操作
不过,您可能想看看
引用文件
“本地主机”可以通过使用委托更改为其他主机。这允许在两个远程主机之间或完全在一台远程计算机上进行复制
你基本上会得到这样的结果:
---
- 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以及您可能想要查看的/copy方法。只有在源服务器kube master或kube节点中启用rsync时,才能使用synchronize模块 方法1:要从主服务器推送,需要在主服务器中启用rsync 同步默认情况下使用推送模式
- hosts: nodes
tasks:
- name: Transfer file from master to nodes
synchronize:
src: /src/path/to/file
dest: /dest/path/to/file
delegate_to: "{{ master }}"
方法2:使用获取和复制模块
希望这有帮助 只有在源服务器kube master(在您的案例中)或kube节点中启用rsync时,才能使用同步模块 方法1:要从主服务器推送,需要在主服务器中启用rsync 同步默认情况下使用推送模式
- hosts: nodes
tasks:
- name: Transfer file from master to nodes
synchronize:
src: /src/path/to/file
dest: /dest/path/to/file
delegate_to: "{{ master }}"
方法2:使用获取和复制模块
希望这有帮助
- hosts: all
tasks:
- name: Fetch the file from the master to ansible
run_once: yes
fetch: src=/src/path/to/file dest=temp/ flat=yes
when: "{{ ansible_hostname == 'master' }}"
- name: Copy the file from the ansible to nodes
copy: src=temp/file dest=/dest/path/to/file
when: "{{ ansible_hostname != 'master' }}"