splunk / ansible-role-for-splunk

Splunk@Splunk's Ansible role for installing Splunk, upgrading Splunk, and installing apps/addons on Splunk deployments (VM/bare metal)
Apache License 2.0
147 stars 103 forks source link

configure_dmc.yml - multiple issues in "Configure systems as search peers to be monitored except indexers" task #225

Open igsher opened 6 months ago

igsher commented 6 months ago

Issues with "Configure systems as search peers to be monitored except indexers" in configure_dmc.yml:

  1. The task fails if 'splunk add search-server' command fails with error "A peer with uri of https://<>:8089 already exists.", instead of ignoring the error.
  2. The task attempts to add the node it's running on as it's own search peer and fails. (duplicate of issue #214)

Proposed fix:

- name: Configure systems as search peers to be monitored except indexers
  ansible.builtin.shell: |
    {{ splunk_home }}/bin/splunk add search-server https://{{ item }}:{{ splunkd_port }} -auth "{{ splunk_auth }}" -remoteUsername "{{ splunk_admin_username }}" -remotePassword "{{ splunk_admin_password }}"
  loop: "{{ query('inventory_hostnames', 'all:!indexer')|difference([inventory_hostname]) }}"
  become: true
  become_user: "{{ splunk_nix_user }}"
  register: dmc_add_search_peer_result
  no_log: true
  failed_when:
    - "dmc_add_search_peer_result.rc != 0"
    - "'already exists' not in dmc_add_search_peer_result.stderr"
  changed_when:
    - "'Peer added' in dmc_add_search_peer_result.stdout"