当复制速度慢且远程服务器上未安装 rsync 时,Ansible 复制和同步替代方案

问题描述 投票:0回答:1

我有大约 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
之外,还有其他解决方案吗?

linux bash ansible
1个回答
0
投票

问:“当 copy

 速度慢并且 
rsync
 未安装在远程服务器上时,有替代方案吗?

根据

Ansible:如何优化剧本的运行速度?

创建、传输和解压存档


示例

创建一些测试文件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
    
© www.soinside.com 2019 - 2024. All rights reserved.