Skip to content

Commit 3ae7b92

Browse files
author
P4T12ICK
committed
fix idempotence test
1 parent 8286781 commit 3ae7b92

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

tasks/install_universal_forwarder.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,57 @@
4040
when: not splunk_configured.stat.exists | default(false)
4141
changed_when: false
4242

43-
- name: Stop splunk uf
43+
- name: Check if SplunkForwarder systemd service exists
44+
become: true
45+
stat:
46+
path: /etc/systemd/system/SplunkForwarder.service
47+
register: splunk_systemd_service
48+
49+
- name: Check if SplunkForwarder service is enabled
50+
become: true
51+
command: systemctl is-enabled SplunkForwarder.service
52+
register: splunk_boot_enabled
53+
changed_when: false
54+
failed_when: false
55+
when: splunk_systemd_service.stat.exists
56+
57+
- name: Check if SplunkForwarder service is running (systemd managed)
58+
become: true
59+
command: systemctl is-active SplunkForwarder.service
60+
register: splunk_service_status
61+
changed_when: false
62+
failed_when: false
63+
when: splunk_systemd_service.stat.exists and (splunk_boot_enabled.rc | default(1) != 0)
64+
65+
- name: Stop splunk uf (systemd managed, before enabling boot-start)
66+
become: true
67+
systemd:
68+
name: SplunkForwarder
69+
state: stopped
70+
when: splunk_systemd_service.stat.exists and (splunk_boot_enabled.rc | default(1) != 0) and splunk_service_status.rc == 0
71+
72+
- name: Check if splunk is running (not systemd managed)
73+
become: true
74+
shell: sudo -u splunkfwd /opt/splunkforwarder/bin/splunk status
75+
register: splunk_status_cmd
76+
changed_when: false
77+
failed_when: false
78+
when: not splunk_systemd_service.stat.exists
79+
80+
- name: Stop splunk uf (not yet systemd managed)
4481
become: true
4582
shell: sudo -u splunkfwd /opt/splunkforwarder/bin/splunk stop
83+
changed_when: false
84+
failed_when: false
85+
when: >
86+
not splunk_systemd_service.stat.exists and
87+
splunk_status_cmd is defined and
88+
'running' in (splunk_status_cmd.stdout | default(''))
4689
4790
- name: setup to start at boot
4891
become: true
4992
command: "/opt/splunkforwarder/bin/splunk enable boot-start"
93+
when: not splunk_systemd_service.stat.exists or (splunk_systemd_service.stat.exists and splunk_boot_enabled.rc != 0)
5094

5195
- name: Start splunk uf
5296
become: true

0 commit comments

Comments
 (0)