linux - 使用 Ansible 将特定文件复制到特定服务器
问题描述
我有 2 个文件。文件 A 和文件 B。现在创建 2 个服务器后,我只想将文件 A 推送到 server1,将文件 B 推送到 server2。
我下面的解决方案适用于 2 个文件。但是当我必须将此模型扩展到 10 台以上的服务器时,它的效率并不高。
- name: Copy file with owner and permissions
copy:
src: /srv/myfiles/serverA.file
dest: /my/destination
when: "serverA" in inventory_hostname
有人可以指出如何更有效地使用 Ansible
文件 A 到服务器 A 文件 B 到服务器 B 文件 C 到服务器 C 文件 Z 到服务器 Z 来更有效地完成以下场景。
解决方案
If your server names host1, host2, host3
In Control node your files are in /tmp
host1.txt
host2.txt
host3.txt
The playbook to copy the files to respective host's /tmp/ :
- hosts: all
gather_facts: no
tasks:
- copy:
src: "/tmp/{{ item }}"
dest: /tmp/
with_lines: ls /tmp
when: inventory_hostname in item
Depending on the hostname and file name change the logic if required.
推荐阅读
- javascript - 在画布上创建纹理
- html - 如何子导航栏css?
- python - python:(请所有专家帮忙)我如何编写一个可以命令和执行python函数的聊天机器人?
- swiftui - SwiftUI - 如何在另一个视图中响应 TextField onCommit?
- html - 放置在背景图像上时按钮不起作用?
- c# - Unity 检查器不显示 XML 文档 (
) 作为工具提示 - javascript - ZXing force 安卓设备上的后置摄像头?
- javascript - 错误消息“app.js:1 Uncaught TypeError: window.addEventListner is not a function at app.js:1”
- php - nginx 工作正常,但 php7.2-fpm 不能正常工作
- c++ - 从二进制文件中读取无符号整数