作为用户,我想将文件从节点1复制到节点2。复制模块+ proxy_to
是否可以以下是我正在尝试做的事情。 Playbook正在从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
答案 0 :(得分:2)
简短的回答是否:您将无法使用keep-alive
44782
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44784
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44786
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44788
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44790
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44792
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44794
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44796
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44798
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
keep-alive
44800
127.0.0.1 - - [10/Jul/2019 16:09:09] "POST / HTTP/1.1" 200 -
模块来完成此操作。
不过,您可能想看看synchronize
module
引用文档
可以使用委托_to将“本地主机”更改为其他主机。这样一来,便可以在两个远程主机之间复制,也可以在一个远程计算机上完全复制。
基本上,您最终会得到类似的东西:
copy
编辑,我刚刚发现this article引用了---
- 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
以及您可能要查看的fetch
/ copy方法。
答案 1 :(得分:2)
仅当在源服务器(在您的情况下为kube master)或kube节点中启用rsync时,才可以使用syncize模块。
默认情况下同步使用push
模式
- hosts: nodes
tasks:
- name: Transfer file from master to nodes
synchronize:
src: /src/path/to/file
dest: /dest/path/to/file
delegate_to: "{{ master }}"
- 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' }}"
希望这会有所帮助。