0

i want to synchronize (copy) files between two remote hosts :.

Under my playbook , i'm running my tasks on several groups relativley to every task case.

My playbook looks like this :

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

My inventory file looks like this :

[myHosts]
myGroupA
myGroupB
myGroupC

Under myRole , i ve this task :

 - 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 }}"

As you can see : i want to transfer file from my "buildServer_host" to the re other remote destination which is only the group "myGroupB"

This fails , and i ve no idea why .

It seems like it doen't understand this : ansible_host in groups['myGroupB'] as a destination host

Suggestions ?

firasKoubaa
  • 6,439
  • 25
  • 79
  • 148

1 Answers1

-1

The delegate_to is more than enough you don't need the when condition as the delegation would be done on the host you have selected in the delegate_to value.

error404
  • 2,684
  • 2
  • 13
  • 21