Skip to content

Master node count check conflates separate clusters deployed in same run #143

@Oddly

Description

@Oddly

Summary

In roles/elasticsearch/tasks/main.yml the task Count master nodes reads the
globally-accumulated Ansible group elasticsearch_role_master instead of
scoping to the hosts of the current play. When two Elasticsearch clusters (a
primary cluster and a separate monitoring cluster) are deployed from the same
ansible-playbook invocation — both running the same role — group_by appends
hosts from all plays to the same global group. The assertion that asserts an
odd master count then sees the sum across both clusters, not the count of the
current cluster.

Reproduction

  1. Inventory with two cluster groups, e.g.:

    [elasticsearch]
    master-001
    master-002
    master-003
    
    [elasticsearch_mon]
    monitor-001   # single-node monitoring cluster, also master-eligible
  2. Playbook that runs oddly.elasticstack.elasticsearch on both groups
    in the same run (separate plays).

  3. Deploy passes the main cluster (3 masters, odd). During the monitor
    cluster play, group_by adds monitor-001 to the same
    elasticsearch_role_master group. Count master nodes now returns 4.

  4. Check count of master nodes fails:

    There must be an odd count of master nodes. You have 4
    

Expected

Each cluster's master count is evaluated against the hosts in the current play
only. A 3-node main cluster passes (3 is odd). A 1-node monitor cluster also
passes (1 is odd).

Suggested fix

Scope the count to ansible_play_hosts_all (the hosts of the current play):

- name: Count master nodes
  ansible.builtin.set_fact:
-   elasticsearch_count_of_master_nodes: "{{ groups['elasticsearch_role_master'] | length }}"
+   elasticsearch_count_of_master_nodes: >-
+     {{ ansible_play_hosts_all | intersect(groups['elasticsearch_role_master'] | default([])) | length }}

Semantics: count the master-eligible nodes among the hosts of this play,
which is the cluster being deployed.

Environment

  • Collection: oddly.elasticstack current main
  • Ansible 2.19.x
  • Two-cluster (main + monitoring) setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions