【发布时间】:2019-08-15 16:07:09
【问题描述】:
我想将特定文件从 localhost 复制到特定远程
服务器。
示例:
file1 ---- server1
file2 ---- server2
file3 ---- server3
已尝试以下解决方案,但它会遍历所有服务器并将文件复制到所有服务器。
部署.yaml
---
- hosts: dev
gather_facts: True
vars:
version: 1.0.0
tasks:
- name: "copying the service files to remote hosts"
copy:
src: ./abc/{{ item.service }}/{{ item.build }}-{{ version }}.zip
dest: ~/{{ item.build }}-{{ version }}.zip
force: yes
delegate_to: "{{ item.service }}"
with_items:
- { service: "abc", build: "abc-service" }
- { service: "bcd" , build: "bcd-service" }
- { service: "mvn" , build: "mvn-service" }
- { service: "ansible" , build: "ans-service" }
库存
[dev]
abc ansible_ssh_host=12.xx.xx.6 ansible_user=dev
bcd ansible_ssh_host=12.xx.xx.7 ansible_user=dev
mvn ansible_ssh_host=12.xx.xx.3 ansible_user=dev
ansible ansible_ssh_host=12.xx.xx.8 ansible_user=dev
【问题讨论】: