Skip to content

Commit 266d630

Browse files
author
Mason Morales
authored
Merge pull request #22 from splunk/add_shc
Squashed another systemd bug related to full installs and added SHC deployment support
2 parents 7b1be38 + ff19f49 commit 266d630

File tree

7 files changed

+143
-61
lines changed

7 files changed

+143
-61
lines changed

playbooks/splunk_shc_deploy.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Example playbook to install splunk and configure a basic SHC
2+
# Ensure that the following vars are configured: ansible_user, ansible_ssh_private_key_file, splunk_admin_password, splunk_user_seed: true
3+
- hosts:
4+
- shdeployer
5+
roles:
6+
- ../roles/splunk
7+
vars:
8+
- deployment_task: check_splunk.yml
9+
10+
- hosts:
11+
- shdeployer
12+
roles:
13+
- ../roles/splunk
14+
vars:
15+
- deployment_task: configure_shc_deployer.yml
16+
17+
- hosts:
18+
- shc
19+
roles:
20+
- ../roles/splunk
21+
vars:
22+
- deployment_task: check_splunk.yml
23+
24+
- hosts:
25+
- shc
26+
roles:
27+
- ../roles/splunk
28+
vars:
29+
- deployment_task: configure_shc_members.yml
30+
31+
- hosts:
32+
- shc
33+
roles:
34+
- ../roles/splunk
35+
vars:
36+
- deployment_task: configure_shc_captain.yml

roles/splunk/defaults/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
# defaults file for splunk role
33
# Anything that is undefined here should be configured. I recommend setting the values in your group_vars under an all.yml file.
4+
systemd_boot: false # Do NOT change the value of this. It automatically gets changed in main.yml if the role finds an existing systemd file configured for splunk.
45
slack_channel: undefined
56
slack_token: undefined
67
splunk_home: auto_determined # This gets set by main.yml but we have to define it here or Ansible will complain that it is undefined
@@ -31,6 +32,16 @@ git_key: undefined # Path to SSH key for cloning repositories - Note that this m
3132
git_project: undefined
3233
git_version: master # Configure default version to clone, overridable inside the git_apps dictionary within host_vars
3334
splunk_app_deploy_path: undefined # Path under $SPLUNK_HOME/ to deploy apps to - Note that this may be set in group_vars, host_vars, playbook vars, or inside the git_apps dictionary within host_vars
35+
# SHC Vars
36+
splunk_shc_key: mypass4symmkey
37+
splunk_shc_label: myshc
38+
splunk_shc_rf: 3
39+
splunk_shc_rep_port: 8100
40+
splunk_shc_target_group: shc
41+
splunkd_port: 8089
42+
splunk_shc_deployer: "{{ groups['shdeployer'] | first }}" # If you manage multiple SHCs, configure the var value in group_vars
43+
splunk_shc_uri_list: "{% for h in groups[splunk_shc_target_group] %}https://{{ hostvars[h].ansible_fqdn }}:{{ splunkd_port }}{% if not loop.last %},{% endif %}{% endfor %}" # If you manage multiple SHCs, configure the var value in group_vars
44+
# Linux and scripting related vars
3445
add_crashlog_script: false # Set to true to install a script and cron job to automatically cleanup splunk crash logs older than 7 days
3546
add_diag_script: false # Set to true to install a script and cron job to automatically cleanup splunk diag files older than 30 days
3647
add_pstack_script: false # Set to true to install a pstack generation script for troubleshooting purposes in $SPLUNK_HOLME/genpstacks.sh
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Bring up cluster captain
3+
command: "{{ splunk_home }}/bin/splunk bootstrap shcluster-captain -servers_list {{ splunk_shc_uri_list }} -auth {{ splunk_auth }}"
4+
become: yes
5+
become_user: "{{ splunk_nix_user }}"
6+
run_once: true
7+
no_log: true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Configure shclustering stanza for deployer
3+
ini_file:
4+
path: "{{ splunk_home }}/etc/system/local/server.conf"
5+
section: shclustering
6+
option: "{{ item.option }}"
7+
value: "{{ item.value }}"
8+
become: yes
9+
become_user: "{{ splunk_nix_user }}"
10+
notify: restart splunk
11+
loop:
12+
- { option: "pass4SymmKey", value: "{{ splunk_shc_key }}" }
13+
- { option: "shcluster_label", value: "{{ splunk_shc_label }}" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Initialize shc config
3+
command: "{{ splunk_home }}/bin/splunk init shcluster-config -auth {{ splunk_auth }} -mgmt_uri https://{{ ansible_fqdn }}:{{ splunkd_port }} -replication_port {{ splunk_shc_rep_port }} -replication_factor {{ splunk_shc_rf }} -conf_deploy_fetch_url https://{{ splunk_shc_deployer }}:{{ splunkd_port }} -secret {{ splunk_shc_key }} -shcluster_label {{ splunk_shc_label }}"
4+
become: yes
5+
become_user: "{{ splunk_nix_user }}"
6+
notify: restart splunk
7+
no_log: true

roles/splunk/tasks/configure_splunk_boot.yml

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,73 @@
11
---
22
# Note: Splunk must be stopped when creating or altering systemd related configurations for it
3-
- name: Check if Splunk needs to be stopped if boot-start isn't configured as Ansible expects (or boot-start is not configured at all)
4-
command: "{{ splunk_home }}/bin/splunk status"
5-
register: splunk_status
6-
become: yes
7-
become_user: "{{ splunk_nix_user }}"
8-
changed_when: false
9-
failed_when: false
10-
when: >
11-
(systemd_boot.stat.exists and splunk_use_initd) or
12-
(initd_boot.stat.exists and not splunk_use_initd) or
13-
(not systemd_boot.stat.exists and not initd_boot.stat.exists and not splunk_use_initd)
14-
15-
- name: Block to stop splunk when systemd was detected but init.d is configured in Ansible
3+
- name: Block for checking boot-start when an existing Splunk installation has been found
164
block:
17-
- name: Stop Splunkd via systemd service name to prepare for conversion to init.d
18-
service:
19-
name: Splunkd
20-
state: stopped
21-
become: yes
22-
when:
23-
- "'full' in group_names"
5+
6+
- name: Check if Splunk needs to be stopped if boot-start isn't configured as Ansible expects (or boot-start is not configured at all)
7+
command: "{{ splunk_home }}/bin/splunk status"
8+
register: splunk_status
9+
become: yes
10+
become_user: "{{ splunk_nix_user }}"
11+
changed_when: false
12+
failed_when: false
13+
when: >
14+
((systemd_boot and splunk_use_initd) or
15+
(initd_boot.stat.exists and not splunk_use_initd) or
16+
(not systemd_boot and not initd_boot.stat.exists and not splunk_use_initd))
2417
25-
- name: Stop SplunkForwarder via systemd service name to prepare for conversion to init.d
26-
service:
27-
name: SplunkForwarder
28-
state: stopped
29-
become: yes
30-
when:
31-
- "'uf' in group_names"
32-
when:
33-
- systemd_boot.stat.exists and splunk_use_initd
34-
- splunk_status.stdout != 'splunkd is not running.'
18+
- name: Block to stop splunk when systemd was detected but init.d is configured in Ansible
19+
block:
20+
- name: Stop Splunkd via systemd service name to prepare for conversion to init.d
21+
service:
22+
name: Splunkd
23+
state: stopped
24+
become: yes
25+
when:
26+
- "'full' in group_names"
3527

36-
- name: Stop Splunk via init.d to prepare for conversion to systemd
37-
service:
38-
name: splunk
39-
state: stopped
40-
become: yes
41-
when:
42-
- initd_boot.stat.exists and not splunk_use_initd
43-
- splunk_status.stdout != 'splunkd is not running.'
28+
- name: Stop SplunkForwarder via systemd service name to prepare for conversion to init.d
29+
service:
30+
name: SplunkForwarder
31+
state: stopped
32+
become: yes
33+
when:
34+
- "'uf' in group_names"
35+
when:
36+
- systemd_boot and splunk_use_initd
37+
- splunk_status.stdout != 'splunkd is not running.'
4438

45-
- name: Stop Splunk via command if boot-start is not configured at all and systemd is configured in Ansible
46-
command: "{{ splunk_home }}/bin/splunk stop"
47-
become: yes
48-
when:
49-
- not systemd_boot.stat.exists
50-
- not initd_boot.stat.exists
51-
- not splunk_use_initd
52-
- splunk_status.stdout != 'splunkd is not running.'
39+
- name: Stop Splunk via init.d to prepare for conversion to systemd
40+
service:
41+
name: splunk
42+
state: stopped
43+
become: yes
44+
when:
45+
- initd_boot.stat.exists and not splunk_use_initd
46+
- splunk_status.stdout != 'splunkd is not running.'
5347

54-
- name: Disable boot-start if current configuration does not matched expected configuration
55-
shell: "{{ splunk_home }}/bin/splunk disable boot-start"
56-
become: yes
57-
when: >
58-
(systemd_boot.stat.exists and splunk_use_initd) or
59-
(initd_boot.stat.exists and not splunk_use_initd)
48+
- name: Stop Splunk via command if boot-start is not configured at all and systemd is configured in Ansible
49+
command: "{{ splunk_home }}/bin/splunk stop"
50+
become: yes
51+
when:
52+
- not systemd_boot
53+
- not initd_boot.stat.exists
54+
- not splunk_use_initd
55+
- splunk_status.stdout != 'splunkd is not running.'
56+
57+
- name: Disable boot-start if current configuration does not matched expected configuration
58+
shell: "{{ splunk_home }}/bin/splunk disable boot-start"
59+
become: yes
60+
when: >
61+
(systemd_boot and splunk_use_initd) or
62+
(initd_boot.stat.exists and not splunk_use_initd)
63+
64+
when: splunkd_found.stat.exists
6065

6166
- name: Enable splunk boot-start via initd
6267
shell: "{{ splunk_home }}/bin/splunk enable boot-start -user {{ splunk_nix_user }} -systemd-managed 0 --answer-yes --auto-ports --no-prompt --accept-license"
6368
become: yes
64-
when:
65-
- splunk_use_initd
66-
- systemd_boot.stat.exists or not initd_boot.stat.exists
69+
when:
70+
- splunk_use_initd and not initd_boot.stat.exists
6771
notify:
6872
- set ulimits in init.d
6973
- reload systemctl daemon
@@ -72,9 +76,8 @@
7276
- name: Enable splunk boot-start via systemd
7377
shell: "{{ splunk_home }}/bin/splunk enable boot-start -user {{ splunk_nix_user }} -systemd-managed 1 --answer-yes --auto-ports --no-prompt --accept-license"
7478
become: yes
75-
when:
76-
- not splunk_use_initd
77-
- initd_boot.stat.exists or not systemd_boot.stat.exists
79+
when:
80+
- not splunk_use_initd and not systemd_boot
7881
notify:
7982
- reload systemctl daemon
8083
- start splunk

roles/splunk/tasks/main.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
stat:
1414
path: /etc/systemd/system/Splunkd.service
1515
follow: yes
16-
register: systemd_boot
16+
register: systemd_boot_full
1717
become: yes
1818
when: "'full' in group_names"
1919

@@ -31,10 +31,15 @@
3131
stat:
3232
path: /etc/systemd/system/SplunkForwarder.service
3333
follow: yes
34-
register: systemd_boot
34+
register: systemd_boot_uf
3535
become: yes
3636
when: "'uf' in group_names"
3737

38+
- name: Set systemd_boot var to true if systemd is being used for splunk
39+
set_fact:
40+
systemd_boot: true
41+
when: (systemd_boot_uf.stat is defined and systemd_boot_uf.stat.exists) or (systemd_boot_full.stat is defined and systemd_boot_full.stat.exists)
42+
3843
- name: Check if current boot-start method is init.d
3944
stat:
4045
path: /etc/init.d/splunk
@@ -57,7 +62,7 @@
5762
- "To correct this: Either run configure_splunk_boot.yml or update the value of splunk_use_initd in your group_vars."
5863
when:
5964
- splunkd_found.stat.exists
60-
- (systemd_boot.stat.exists and splunk_use_initd) or (initd_boot.stat.exists and not splunk_use_initd) or (not systemd_boot.stat.exists and not initd_boot.stat.exists)
65+
- (systemd_boot and splunk_use_initd) or (initd_boot.stat.exists and not splunk_use_initd) or (not systemd_boot and not initd_boot.stat.exists)
6166
- not deployment_task == "configure_splunk_boot.yml"
6267

6368
- name: Configure var for splunk init.d service handler

0 commit comments

Comments
 (0)