Ansible:在给定特定主机目标组的情况下,在两个远程主机之间同步文件

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

我想在两个远程主机之间同步(复制)文件:。

在我的剧本中,我正在针对每个任务案例在几个小组中运行我的任务。

我的剧本看起来像这样:

---
- hosts: myHosts
  gather_facts: true
  become: true
  become_user: "{{ ansi_user }}"
  vars:
    - buildServer_host : "127.78.11.04"
  roles:
    #... Different roles
    ...
    - { role: myRole }

我的库存文件如下所示:

[myHosts]
myGroupA
myGroupB
myGroupC

在myRole下,我有这个任务:

 - name: Copy  jars to API server 
   synchronize:
    src: "{{ Workspace_GEN_COLIS }}/{{item.item}}/target/{{item.stdout}}"
    dest: "/opt/application/i99was/{{RCD_DEF_VERSION}}/{{item.item}}.jar"
   with_items: "{{ jarFileNames.results }}"
   when:
    - ansible_host in groups['myGroupB']
   delegate_to: "{{buildServer_host }}"

如您所见:我想将文件从我的“buildServer_host”传输到另一个远程目标,该目标只是“myGroupB”组

这失败了,我不知道为什么。

似乎它不明白这一点:ansible_host in groups['myGroupB']作为目的地主机

建议?

ansible ansible-2.x ansible-inventory ansible-facts
1个回答
-1
投票

delegate_to绰绰有余,您不需要when条件,因为委派将在您在delegate_to值中选择的主机上完成。

© www.soinside.com 2019 - 2024. All rights reserved.