Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mongodb_replicaset): Count voting members #615

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions plugins/modules/mongodb_replicaset.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,11 @@ def main():
debug = module.params['debug']
cluster_cmd = module.params['cluster_cmd']

voting_members = []
for member in members:
if ("votes" in member and member["votes"]) or "votes" not in member:
voting_members.append(member)
# Count voting members
voting_members = sum([1 if not isinstance(m, dict) or m.get("votes", 1) == 1 else 0 for m in members])

if validate and reconfigure is False:
if len(members) <= 2 or len(voting_members) % 2 == 0:
if len(members) <= 2 or voting_members % 2 == 0:
module.fail_json(msg="MongoDB Replicaset validation failed. Invalid number of replicaset members.")
if arbiter_at_index is not None and len(members) - 1 < arbiter_at_index:
module.fail_json(msg="MongoDB Replicaset validation failed. Invalid arbiter index.")
Expand Down
Loading