Skip to content

Commit

Permalink
Merge pull request #867 from splunk/debug-mc-peering
Browse files Browse the repository at this point in the history
Prevent duplicate MC search peers
  • Loading branch information
jmeixensperger authored Dec 9, 2024
2 parents 1083d57 + f6e0486 commit d1c27c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion roles/splunk_monitor/tasks/adding_peers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use_proxy: no
register: distsearch_server_info
no_log: "{{ hide_password }}"

- name: Initialize lists
set_fact:
current_group_list: []
Expand All @@ -28,7 +29,28 @@

- name: Create list of peers
set_fact:
group_list: "{{ (groups['splunk_indexer']| default([])) + (groups['splunk_search_head'] | default([])) + (groups['splunk_search_head_captain'] | default([])) + (groups['splunk_cluster_master'] | default([])) + (groups['splunk_deployment_server']| default([])) + (groups['splunk_license_master'] | default([])) + (groups['splunk_standalone'] | default([])) }}"
group_list: "{{ (groups['splunk_indexer'] | default([])) + (groups['splunk_search_head'] | default([])) + (groups['splunk_search_head_captain'] | default([])) + (groups['splunk_cluster_master'] | default([])) + (groups['splunk_deployment_server']| default([])) + (groups['splunk_license_master'] | default([])) + (groups['splunk_standalone'] | default([])) }}"

- name: Fetch existing peers
splunk_api:
method: GET
url: "/services/search/distributed/peers?output_mode=json&count=0"
cert_prefix: "{{ cert_prefix }}"
username: "{{ splunk.admin_user }}"
password: "{{ splunk.password }}"
svc_port: "{{ splunk.svc_port }}"
status_code: [200]
timeout: 10
return_content: yes
use_proxy: no
register: existing_peers
no_log: "{{ hide_password }}"
retries: "{{ retry_num }}"
delay: "{{ retry_delay }}"

- name: Remove existing peers from group_list
set_fact:
group_list: "{{ group_list | difference(existing_peers['json']['entry'] | selectattr('content.status', 'search', 'Up') | map(attribute='content.peerName') | list) }}"

- name: Update group_list
vars:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
- include_tasks: ../../../roles/splunk_monitor/tasks/adding_peers.yml

- include_tasks: ../../../roles/splunk_common/tasks/set_as_deployment_client.yml
when:
- splunk.deployment_server is defined
Expand Down
2 changes: 2 additions & 0 deletions roles/splunk_monitor/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- name: Flush restart handlers
meta: flush_handlers

- include_tasks: ../../../roles/splunk_monitor/tasks/adding_peers.yml

- name: Fetch server info
splunk_api:
method: GET
Expand Down

0 comments on commit d1c27c4

Please sign in to comment.