Calculate Quorum of Hosts#
Problem#
How do we calculate the quorum of Hosts in a Play?
Solution#
quorum: "{{ ( group['cluster_leaders'] | count / 2) | round(0, 'ceil') | int }}"
Explanation#
A list of Hosts serves as the origin.
- name: Calculate quorum of cluster leaders
ansible.builtin.copy:
content: "{{ ( group['cluster_leaders'] | count / 2) | round(0, 'ceil') | int }}"
dest: /etc/cluster-leader/quorum
Group, Lookup or Query
In our solution, we used a group group['my_group']
but a Lookup or Query may also be suitable when using groups with filters:
"{{ query('inventory_hostnames', 'cluster_leaders:!cluster_followers') }}"