Hi Kai,
I have resolved my issue with group_by. Grouping by primary and non-primary 
and run commands on non-primary hosts. 
Thank you for your suggestions.




On Sunday, April 26, 2020 at 6:02:11 PM UTC-4, Kai Stian Olstad wrote:
>
> On Mon, Apr 20, 2020 at 11:14:23AM -0700, Raj V wrote: 
> > I am a newbie to Ansible and trying to figure out how to synchronize 
> > between 3 hosts based on condition. Below are details: 
> > There are 3 nodes and based on which node is primary (I was able to get 
> a 
> > custom fact set for it) need to delegate to that host (which runs 
> > synchronize from that host to other two hosts). 
> > Custom fact basically is  value 1 or 0 (1 means Primary/Master and 0 
> means 
> > not). 
> > I am unable to get the hostname (primary hostname) value to include into 
> > the synchronize steps. Below is the playbook I have. How do I make 
> > synchronize read the "primary" hostname value to run the next steps. 
> > 
> > --- 
> > 
> > - name: Playbook for rsync 
> >   become: yes 
> >   hosts: clients 
> >   gather_facts: True 
> > 
> >   tasks: 
> >   - name: Task to rsync from Primary server 
> >     synchronize: 
> >       src: "{{ item.source }}" 
> >       dest: "{{ item.dest }}" 
> >     with_items: 
> >       - { source: '/rsynctest/', dest: '/rsynctest/' } 
> >       - { source: '/rsynctest1/', dest: '/rsynctest1/' } 
> >     delegate_to: "{{ ansible_hostname }}" 
> >     when: 
> >       - ansible_local.determine.isprimary  == "1" 
>
> The best thing you can do is create a fact or run a command that can find 
> the 
> name of the host and use that in the when. 
>
> As you have done it here you need to loop over all host, check if they 
> have 
> the variable, check if it 1 and if so get the name. 
>
> -- 
> Kai Stian Olstad 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ef167ac9-11a2-42c0-b79e-c5d9b86f8738%40googlegroups.com.

Reply via email to