現在、2つのホストを持ってグループに動的に追加し、synchronize
タスクの後にwith_together
タスクを使用して2つの要素の3つのリストを使用して、リモートサーバー。with_togetherファッションのホストに対して実行可能なタスク
---
- name: Configure Hosts for Copying
hosts: localhost
gather_facts: no
tasks:
- name: Adding given hosts to new group...
add_host:
name: "{{ item }}"
groups: copy_group
with_items:
- ["remoteDest1", "remoteDest2"]
- name: Copy Files between servers
hosts: copy_group
gather_facts: no
tasks:
- name: Copying files...
synchronize:
src: "{{ item[1] }}"
dest: "{{ item[2] }}"
with_together:
- ["remoteSrc1", "remoteSrc2"]
- ["/tmp/remote/source/one/", "/tmp/remote/source/two/"]
- ["/tmp/remote/dest/one/", "/tmp/remote/dest/two/"]
delegate_to: "{{ item[0] }}"
現在のところ、それは4回の操作で、その結果、両方のサーバーの両方の操作を行います。
は、ここでの考え方に基づい例です。それは1です意味しますremoteDest2
上/tmp/remote/dest/two/
からremoteSrc2
から/tmp/remote/dest/one/
へ
- コピー
/tmp/remote/source/one/
remoteSrc1
からコピー/tmp/remote/source/two/
remoteDest1
上:
私はそうのように同期させる必要がある
: 1比;基本的には、ホストに対してはwith_together
と同じ方法で動作します。
ホストは動的に取得されるため、ホストごとに異なるプレイを行うことはできません。
synchronize
は基本的にrsync
の簡略化されたバージョンであるため、rsync
を使用してこの簡単な解決策がある場合は、非常に感謝します。