|
40 | 40 | when: not splunk_configured.stat.exists | default(false) |
41 | 41 | changed_when: false |
42 | 42 |
|
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) |
44 | 81 | become: true |
45 | 82 | 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('')) |
46 | 89 |
|
47 | 90 | - name: setup to start at boot |
48 | 91 | become: true |
49 | 92 | 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) |
50 | 94 |
|
51 | 95 | - name: Start splunk uf |
52 | 96 | become: true |
|
0 commit comments