# Conditional Delegation to a host for synchronize module

**URL:** <https://forum.ansible.com/t/conditional-delegation-to-a-host-for-synchronize-module/32739>\
**Category:** Ansible Project\
**Created:** [April 20, 2020, 6:14pm UTC](https://forum.ansible.com/t/conditional-delegation-to-a-host-for-synchronize-module/32739 "2020-04-20T18:14:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj\_V](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Raj\_V](https://forum.ansible.com/u/Raj_V)\
**Post date:** [April 20, 2020, 6:14pm UTC](https://forum.ansible.com/t/conditional-delegation-to-a-host-for-synchronize-module/32739/1 "2020-04-20T18:14:23Z")

</div>

Hello,

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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 26, 2020, 10:01pm UTC](https://forum.ansible.com/t/conditional-delegation-to-a-host-for-synchronize-module/32739/2 "2020-04-26T22:01:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Raj\_V](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Raj\_V](https://forum.ansible.com/u/Raj_V)\
**Post date:** [May 5, 2020, 7:52pm UTC](https://forum.ansible.com/t/conditional-delegation-to-a-host-for-synchronize-module/32739/3 "2020-05-05T19:52:27Z")

</div>

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.
