我有大约 1K 台服务器,需要运行这三个命令:
#!/usr/bin/bash
ansible all -m shell -a 'mkdir -pv /root/newimages/'
ansible all -m copy -a 'src=/root/file1.tar dest=/root/newimages/ mode=644'
ansible all -m copy -a 'src=/root/file2.tar dest=/root/newimages/ mode=644'
ansible all -m copy -a 'src=/root/file3.tar dest=/root/newimages/ mode=644'
# until file100.tar
ansible all -m shell -a 'find /root/newimages/ -name "*.tar" -exec docker load -i {} \;'
在开始之前,我知道拥有多个
-m copy fileN.tar
很好,但我找不到如何使用 *.tar
命令行清单复制 ansible
文件。
当我尝试
copy
模块时,它太慢了。当我尝试 synchronize
模块时,问题是某些服务器返回错误,rsync command not found
。
由于所有服务器都没有公共互联网访问权限,因此我无法通过
rsync
或 apt
安装 yum
。我也尝试下载rsync.rpm
文件,但它需要很多依赖项,所以我暂时忽略了安装它。
在上述条件下,除了
copy
和synchronize
之外,还有其他解决方案吗?
问:“当 copy
速度慢并且
rsync
未安装在远程服务器上时,有替代方案吗?” 根据
创建、传输和解压存档
示例
创建一些测试文件via
for i in {1..9} ; do dd if=/dev/random of=tars/${i}.tar bs=4k iflag=fullblock,count_bytes count=10M ; done
tar cvzf tars/files.tar.gz tars/*.tar
还有一个最小的示例手册
---
- hosts: test
become: false
gather_facts: false
tasks:
- name: Copy single files to Remote Node
copy:
src: "tars/{{ item }}.tar"
dest: "/tmp"
mode: 0644
loop: "{{ range(1, 10, 1) }}"
- name: Copy all files archived to Remote Node
copy:
src: "tars/files.tar.gz"
dest: "/tmp"
mode: 0644
- name: Unarchive from Control Node into Remote Node
unarchive:
src: "tars/files.tar.gz"
dest: "/tmp"
mode: 0644
extra_opts: [--strip-components=1, --overwrite]
运行时看起来像
TASK [Copy single files to Remote Node] ***************
changed: [test.example.com] => (item=1)
...
changed: [test.example.com] => (item=9)
(0:00:18.602)
TASK [Copy all files archived to Remote Node] *********
changed: [test.example.com]
(0:00:04.680)
TASK [Unarchive from Control Node into Remote Node] ***
changed: [test.example.com]
(0:00:05.471)
=======================================================
Copy single files to Remote Node --------------- 18.60s
Copy all files archived to Remote Node ---------- 4.68s
Unarchive from Control Node into Remote Node ---- 5.47s