[英]Copying files from the specified hosts to others in ansible
我的清單文件中有三台主機
[controller]
1.1.1.1
2.2.2.2
3.3.3.3
我在group_var文件夾中有一個變量,用於指定主節點
master=1.1.1.1
sql.conf在所有3個控制器主機的主目錄(/home/ubuntu/sql.conf)中都可用。
現在,我需要將文件(test.txt)從master復制到其他人。 有什么辦法可以將文件從一台特定的服務器復制到另一台。
我正在嘗試這樣,但無法實現。
- hosts: all
sudo: yes
tasks:
- name: copy files
local_action: command rsync -a /home/ubuntu/test.txt {{ master }}:///home/ubuntu/test.txt
一種選擇是使用fetch
模塊將文件從主節點復制到本地節點,然后通常使用copy
模塊將該文件分發到其他節點。 就像是:
- hosts: master
tasks:
- fetch:
src: /path/to/myfile.txt
dest: tmp/
- hosts: all:!master
tasks:
- copy:
src: tmp/master/myfile.txt
dest: /path/to/myfile.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.