From f62856ac5882f66154693ffa1992a5f37f3a3bb1 Mon Sep 17 00:00:00 2001 From: Aditya Pingle Date: Tue, 2 Apr 2024 11:52:34 -0700 Subject: [PATCH 1/7] check if UDS file exists instead of tcp flag value; --- roles/splunk_common/handlers/restart_splunk.yml | 7 ++++++- roles/splunk_common/tasks/main.yml | 7 ++++++- roles/splunk_common/tasks/set_certificate_prefix.yml | 7 ++++++- roles/splunk_common/tasks/start_splunk.yml | 7 ++++++- roles/splunk_common/tasks/wait_for_splunk_process.yml | 7 ++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/roles/splunk_common/handlers/restart_splunk.yml b/roles/splunk_common/handlers/restart_splunk.yml index 0e3e1cf5..566200b1 100644 --- a/roles/splunk_common/handlers/restart_splunk.yml +++ b/roles/splunk_common/handlers/restart_splunk.yml @@ -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 diff --git a/roles/splunk_common/tasks/main.yml b/roles/splunk_common/tasks/main.yml index 065a0b4a..15d57d3c 100644 --- a/roles/splunk_common/tasks/main.yml +++ b/roles/splunk_common/tasks/main.yml @@ -122,8 +122,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 diff --git a/roles/splunk_common/tasks/set_certificate_prefix.yml b/roles/splunk_common/tasks/set_certificate_prefix.yml index c1a28b7b..6a4a54f4 100644 --- a/roles/splunk_common/tasks/set_certificate_prefix.yml +++ b/roles/splunk_common/tasks/set_certificate_prefix.yml @@ -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 }}" @@ -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 }}" diff --git a/roles/splunk_common/tasks/start_splunk.yml b/roles/splunk_common/tasks/start_splunk.yml index 0508961f..6988ceb3 100644 --- a/roles/splunk_common/tasks/start_splunk.yml +++ b/roles/splunk_common/tasks/start_splunk.yml @@ -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 diff --git a/roles/splunk_common/tasks/wait_for_splunk_process.yml b/roles/splunk_common/tasks/wait_for_splunk_process.yml index 6f3e53c6..3d9a77c2 100644 --- a/roles/splunk_common/tasks/wait_for_splunk_process.yml +++ b/roles/splunk_common/tasks/wait_for_splunk_process.yml @@ -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 From 586c80640ef8b62e7095d6b9752398f438cf111a Mon Sep 17 00:00:00 2001 From: Aditya Pingle Date: Tue, 2 Apr 2024 11:56:33 -0700 Subject: [PATCH 2/7] add python requirements play; --- .../splunk_common/tasks/install_python_requirements.yml | 9 +++++++++ roles/splunk_common/tasks/main.yml | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 roles/splunk_common/tasks/install_python_requirements.yml diff --git a/roles/splunk_common/tasks/install_python_requirements.yml b/roles/splunk_common/tasks/install_python_requirements.yml new file mode 100644 index 00000000..984829b3 --- /dev/null +++ b/roles/splunk_common/tasks/install_python_requirements.yml @@ -0,0 +1,9 @@ +--- +- name: Check if requests_unixsocket exists + command: "pip list | grep 'requests-unixsocket'" + register: requests_unixsocket_check + +- name: Install missing requests_unixsocket + ansible.builtin.pip: + name: "requests_unixsocket" + when: requests_unixsocket_check.stdout | length == 0 or requests_unixsocket_check.stdout.find("requests-unixsocket") == -1 diff --git a/roles/splunk_common/tasks/main.yml b/roles/splunk_common/tasks/main.yml index 15d57d3c..dc39109b 100644 --- a/roles/splunk_common/tasks/main.yml +++ b/roles/splunk_common/tasks/main.yml @@ -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") From 4d2e7e9aca037f278eb0b9d17121b98adc5419fc Mon Sep 17 00:00:00 2001 From: Aditya Pingle Date: Tue, 2 Apr 2024 12:02:51 -0700 Subject: [PATCH 3/7] fix syntax for stat; add pip3 support; --- roles/splunk_common/handlers/restart_splunk.yml | 6 +++--- roles/splunk_common/tasks/install_python_requirements.yml | 6 ++++++ roles/splunk_common/tasks/main.yml | 6 +++--- roles/splunk_common/tasks/set_certificate_prefix.yml | 6 +++--- roles/splunk_common/tasks/start_splunk.yml | 6 +++--- roles/splunk_common/tasks/wait_for_splunk_process.yml | 6 +++--- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/roles/splunk_common/handlers/restart_splunk.yml b/roles/splunk_common/handlers/restart_splunk.yml index 566200b1..3eb7e068 100644 --- a/roles/splunk_common/handlers/restart_splunk.yml +++ b/roles/splunk_common/handlers/restart_splunk.yml @@ -24,9 +24,9 @@ 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 + stat: + path: "/opt/splunkforwarder/var/run/splunk/cli.socket" + register: uds_socket_exists - name: "Wait for splunkd management port" wait_for: diff --git a/roles/splunk_common/tasks/install_python_requirements.yml b/roles/splunk_common/tasks/install_python_requirements.yml index 984829b3..3fc54351 100644 --- a/roles/splunk_common/tasks/install_python_requirements.yml +++ b/roles/splunk_common/tasks/install_python_requirements.yml @@ -1,4 +1,10 @@ --- +- name: Install and upgrade pip + pip: + name: pip + extra_args: --upgrade + executable: pip3 + - name: Check if requests_unixsocket exists command: "pip list | grep 'requests-unixsocket'" register: requests_unixsocket_check diff --git a/roles/splunk_common/tasks/main.yml b/roles/splunk_common/tasks/main.yml index dc39109b..9a4be50b 100644 --- a/roles/splunk_common/tasks/main.yml +++ b/roles/splunk_common/tasks/main.yml @@ -125,9 +125,9 @@ - include_tasks: start_splunk.yml - name: Check if UDS file exists - stat: - path: "/opt/splunkforwarder/var/run/splunk/cli.socket" - register: uds_socket_exists + stat: + path: "/opt/splunkforwarder/var/run/splunk/cli.socket" + register: uds_socket_exists - include_tasks: set_certificate_prefix.yml when: not uds_socket_exists.stat.exists diff --git a/roles/splunk_common/tasks/set_certificate_prefix.yml b/roles/splunk_common/tasks/set_certificate_prefix.yml index 6a4a54f4..19abcbf0 100644 --- a/roles/splunk_common/tasks/set_certificate_prefix.yml +++ b/roles/splunk_common/tasks/set_certificate_prefix.yml @@ -1,8 +1,8 @@ --- - name: Check if UDS file exists - stat: - path: "/opt/splunkforwarder/var/run/splunk/cli.socket" - register: uds_socket_exists + stat: + path: "/opt/splunkforwarder/var/run/splunk/cli.socket" + register: uds_socket_exists - name: "Test basic https endpoint" uri: diff --git a/roles/splunk_common/tasks/start_splunk.yml b/roles/splunk_common/tasks/start_splunk.yml index 6988ceb3..88220dd1 100644 --- a/roles/splunk_common/tasks/start_splunk.yml +++ b/roles/splunk_common/tasks/start_splunk.yml @@ -51,9 +51,9 @@ - ansible_os_family == "Windows" - name: Check if UDS file exists - stat: - path: "/opt/splunkforwarder/var/run/splunk/cli.socket" - register: uds_socket_exists + stat: + path: "/opt/splunkforwarder/var/run/splunk/cli.socket" + register: uds_socket_exists - name: "Wait for splunkd management port" wait_for: diff --git a/roles/splunk_common/tasks/wait_for_splunk_process.yml b/roles/splunk_common/tasks/wait_for_splunk_process.yml index 3d9a77c2..439c8a1d 100644 --- a/roles/splunk_common/tasks/wait_for_splunk_process.yml +++ b/roles/splunk_common/tasks/wait_for_splunk_process.yml @@ -6,9 +6,9 @@ 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 + 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: From 061558365d8465faa298fccdbf1149a3774ab524 Mon Sep 17 00:00:00 2001 From: Aditya Pingle Date: Wed, 3 Apr 2024 10:26:01 -0700 Subject: [PATCH 4/7] support pip and pip3 --- .../tasks/install_python_requirements.yml | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/roles/splunk_common/tasks/install_python_requirements.yml b/roles/splunk_common/tasks/install_python_requirements.yml index 3fc54351..8d10246a 100644 --- a/roles/splunk_common/tasks/install_python_requirements.yml +++ b/roles/splunk_common/tasks/install_python_requirements.yml @@ -1,15 +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 requests_unixsocket exists - command: "pip list | grep 'requests-unixsocket'" - register: requests_unixsocket_check +- 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.stdout | length == 0 or requests_unixsocket_check.stdout.find("requests-unixsocket") == -1 + 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) From 07f9908a2836391abfaeb7d747341d7278598b5a Mon Sep 17 00:00:00 2001 From: Aditya Pingle Date: Thu, 4 Apr 2024 12:48:52 -0700 Subject: [PATCH 5/7] debug;l --- roles/splunk_common/tasks/install_python_requirements.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/roles/splunk_common/tasks/install_python_requirements.yml b/roles/splunk_common/tasks/install_python_requirements.yml index 8d10246a..315996d5 100644 --- a/roles/splunk_common/tasks/install_python_requirements.yml +++ b/roles/splunk_common/tasks/install_python_requirements.yml @@ -20,9 +20,3 @@ - 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) From aafd0198c91e333cd09e63f8498854bab082a762 Mon Sep 17 00:00:00 2001 From: Olivia Yan Date: Fri, 12 Apr 2024 21:57:26 -0400 Subject: [PATCH 6/7] Split configure_mgmt_port since require restart --- .../splunk_common/tasks/configure_mgmt_port.yml | 17 ----------------- roles/splunk_common/tasks/main.yml | 2 ++ roles/splunk_common/tasks/set_mgmt_port.yml | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 roles/splunk_common/tasks/set_mgmt_port.yml diff --git a/roles/splunk_common/tasks/configure_mgmt_port.yml b/roles/splunk_common/tasks/configure_mgmt_port.yml index a50a2579..59abc779 100644 --- a/roles/splunk_common/tasks/configure_mgmt_port.yml +++ b/roles/splunk_common/tasks/configure_mgmt_port.yml @@ -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" @@ -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 - diff --git a/roles/splunk_common/tasks/main.yml b/roles/splunk_common/tasks/main.yml index 9a4be50b..c624b3e6 100644 --- a/roles/splunk_common/tasks/main.yml +++ b/roles/splunk_common/tasks/main.yml @@ -76,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" diff --git a/roles/splunk_common/tasks/set_mgmt_port.yml b/roles/splunk_common/tasks/set_mgmt_port.yml new file mode 100644 index 00000000..cfc9cd14 --- /dev/null +++ b/roles/splunk_common/tasks/set_mgmt_port.yml @@ -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 From f1046d31d2bd971c273afd2cc08cfb6accbd934f Mon Sep 17 00:00:00 2001 From: Olivia Yan Date: Mon, 15 Apr 2024 16:03:06 -0400 Subject: [PATCH 7/7] Add checks for installing missing requests_unixsocket --- roles/splunk_common/tasks/install_python_requirements.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/roles/splunk_common/tasks/install_python_requirements.yml b/roles/splunk_common/tasks/install_python_requirements.yml index 315996d5..8d10246a 100644 --- a/roles/splunk_common/tasks/install_python_requirements.yml +++ b/roles/splunk_common/tasks/install_python_requirements.yml @@ -20,3 +20,9 @@ - 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)