Skip to content

Commit

Permalink
Merge pull request #810 from splunk/check-for-UDS-file-and-not-tcp-flag
Browse files Browse the repository at this point in the history
Check for uds file and not UDS flag
  • Loading branch information
ruomeiy-splunk committed Apr 16, 2024
1 parent dfdee89 commit 6d3604a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 22 deletions.
7 changes: 6 additions & 1 deletion roles/splunk_common/handlers/restart_splunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
state: restarted
when: splunk.enable_service and not ansible_system is match("Linux")

- name: Check if UDS file exists
stat:
path: "/opt/splunkforwarder/var/run/splunk/cli.socket"
register: uds_socket_exists

- name: "Wait for splunkd management port"
wait_for:
port: "{{ splunk.svc_port }}"
when: splunk.splunk_http_enabled|bool == true
when: not uds_socket_exists.stat.exists
17 changes: 0 additions & 17 deletions roles/splunk_common/tasks/configure_mgmt_port.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
---
- name: Set mgmt port
ini_file:
dest: "{{ splunk.home }}/etc/system/local/web.conf"
section: settings
option: "mgmtHostPort"
value: "0.0.0.0:{{ splunk.svc_port }}"
owner: "{{ splunk.user }}"
group: "{{ splunk.group }}"
when:
- "'svc_port' in splunk"
register: set_mgmt_port

- name: Configure to set Mgmt Mode as auto (Allows UDS)
ini_file:
dest: "{{ splunk.home }}/etc/system/local/server.conf"
Expand All @@ -30,8 +18,3 @@
owner: "{{ splunk.user }}"
group: "{{ splunk.group }}"
when: splunk.role == "splunk_universal_forwarder" and splunk.splunk_http_enabled|bool == true

# Restart only when Splunk is running and when any of the above have changed
- include_tasks: ../handlers/restart_splunk.yml
when: set_mgmt_port is changed

28 changes: 28 additions & 0 deletions roles/splunk_common/tasks/install_python_requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: Check if requests_unixsocket exists
command: "pip list | grep 'requests-unixsocket'"
register: requests_unixsocket_check
ignore_errors: true

- name: Install and upgrade pip
pip:
name: pip
extra_args: --upgrade
executable: pip3
when: requests_unixsocket_check is failed

- name: Check if pip3 unixsocket exits
command: "pip3 list | grep 'requests-unixsocket'"
register: requests_unixsocket_check_py3
when: requests_unixsocket_check is failed
ignore_errors: true

- name: Install missing requests_unixsocket
ansible.builtin.pip:
name: "requests_unixsocket"
when: requests_unixsocket_check is succeeded and (requests_unixsocket_check.stdout | length == 0 or requests_unixsocket_check.stdout.find("requests-unixsocket") == -1)

- name: Install missing requests_unixsocket PY3
ansible.builtin.pip:
name: "requests_unixsocket"
when: requests_unixsocket_check_py3 is succeeded and (requests_unixsocket_check_py3.stdout | length == 0 or requests_unixsocket_check_py3.stdout.find("requests-unixsocket") == -1)
11 changes: 10 additions & 1 deletion roles/splunk_common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
- include_tasks: get_facts.yml

- include_tasks: install_python_requirements.yml

- include_tasks: change_splunk_directory_owner.yml
when:
- ansible_system is match("Linux")
Expand Down Expand Up @@ -74,6 +76,8 @@
- "'http_port' in splunk"
- splunk.http_port | int != 8000

- include_tasks: set_mgmt_port.yml

- include_tasks: set_root_endpoint.yml
when: "'root_endpoint' in splunk and splunk.root_endpoint"

Expand Down Expand Up @@ -122,8 +126,13 @@

- include_tasks: start_splunk.yml

- name: Check if UDS file exists
stat:
path: "/opt/splunkforwarder/var/run/splunk/cli.socket"
register: uds_socket_exists

- include_tasks: set_certificate_prefix.yml
when: splunk.splunk_http_enabled|bool == true
when: not uds_socket_exists.stat.exists

- include_tasks: clean_user_seed.yml

Expand Down
7 changes: 6 additions & 1 deletion roles/splunk_common/tasks/set_certificate_prefix.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
- name: Check if UDS file exists
stat:
path: "/opt/splunkforwarder/var/run/splunk/cli.socket"
register: uds_socket_exists

- name: "Test basic https endpoint"
uri:
url: "https://127.0.0.1:{{ splunk.svc_port }}"
Expand All @@ -8,7 +13,7 @@
timeout: 10
use_proxy: no
register: ssl_enabled
when: splunk.splunk_http_enabled|bool == true
when: not uds_socket_exists.stat.exists
ignore_errors: true
delay: "{{ retry_delay }}"
retries: "{{ retry_num }}"
Expand Down
16 changes: 16 additions & 0 deletions roles/splunk_common/tasks/set_mgmt_port.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Set mgmt port
ini_file:
dest: "{{ splunk.home }}/etc/system/local/web.conf"
section: settings
option: "mgmtHostPort"
value: "0.0.0.0:{{ splunk.svc_port }}"
owner: "{{ splunk.user }}"
group: "{{ splunk.group }}"
when:
- "'svc_port' in splunk"
register: set_mgmt_port

# Restart only when Splunk is running and when any of the above have changed
- include_tasks: ../handlers/restart_splunk.yml
when: set_mgmt_port is changed
7 changes: 6 additions & 1 deletion roles/splunk_common/tasks/start_splunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@
- splunk.enable_service
- ansible_os_family == "Windows"

- name: Check if UDS file exists
stat:
path: "/opt/splunkforwarder/var/run/splunk/cli.socket"
register: uds_socket_exists

- name: "Wait for splunkd management port"
wait_for:
port: "{{ splunk.svc_port }}"
when: splunk.splunk_http_enabled|bool == true
when: not uds_socket_exists.stat.exists

- name: Flush restart handlers
meta: flush_handlers
7 changes: 6 additions & 1 deletion roles/splunk_common/tasks/wait_for_splunk_process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
state: present
when: ansible_system is match("Linux")

- name: Check if UDS file exists
stat:
path: "/opt/splunkforwarder/var/run/splunk/cli.socket"
register: uds_socket_exists

- name: Wait for the Splunk service port to be available
wait_for:
host: 127.0.0.1
port: "{{ splunk.svc_port }}"
timeout: 180
when: splunk.splunk_http_enabled|bool == true
when: not uds_socket_exists.stat.exists

0 comments on commit 6d3604a

Please sign in to comment.