Ansible:将一个唯一文件复制到一组中的每个服务器 [英] Ansible: copying one unique file to each server in a group

查看:25
本文介绍了Ansible:将一个唯一文件复制到一组中的每个服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列编号的文件要由每个服务器单独处理.每个拆分文件使用 linux 拆分然后 xz 压缩以节省传输时间.

I have a series of numbered files to be processed separately by each server. Each split file made using linux split and then xz compressed to save transfer time.

split_001 split_002 split_003 ... split_030

如何使用 ansible 将这些文件推送到一组 30 个服务器?只要每个服务器都有一个唯一的文件,哪个服务器获取哪个文件并不重要.

How can I push these files out to a group of 30 servers with ansible? It does not matter which server gets which file so long as they each have a single unique file.

我使用了 bash 文件,但我正在寻找更好的解决方案.希望使用ansible.然后我计划运行一个 shell 命令来运行一个 at 命令来开始几个小时或几天的计算.

I had used a bash file but I am looking for a better solution. Hopefully using ansible. Then I plan to run a shell command to run an at command to start the several hours or days of computation.

scp -oStrictHostKeyChecking=no bt_5869_001.xz usr13@<ip>:/data/
scp -oStrictHostKeyChecking=no bt_5869_002.xz usr13@<ip>:/data/
scp -oStrictHostKeyChecking=no bt_5869_003.xz usr13@<ip>:/data/
...

http://docs.ansible.com/ansible/copy_module.html

# copy file but iterate through each of the split files
- copy: src=/mine/split_001.xz dest=/data/split_001.xz
- copy: src=/mine/compute dest=/data/ owner=root mode=0755
- copy: src=/mine/start.sh dest=/data/ owner=root mode=0755
- shell: xz -d *.xz
- shell: at -f /data/start.sh now

推荐答案

例如:

  tasks:
    - set_fact:
        padded_host_index: "{{ '{0:03d}'.format(play_hosts.index(inventory_hostname)) }}"

    - copy: src=/mine/split_{{ padded_host_index }}.xz dest=/data/

这篇关于Ansible:将一个唯一文件复制到一组中的每个服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆