【问题标题】:Ansible : sychronize files between two remote hosts given a specific group of hosts destinationAnsible:在给定一组特定主机目标的情况下,在两个远程主机之间同步文件
【发布时间】:2019-02-28 12:06:26
【问题描述】:

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

根据我的剧本,我在多个组上运行我的任务,相对于每个任务案例。

我的剧本如下所示:

---
- 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】:

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

    【讨论】:

    • 我正在使用“delegate_to”来表示我的源服务器,目标处于何时状态
    猜你喜欢
    • 1970-01-01
    • 2022-08-03
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    相关资源
    最近更新 更多