Skip to content

Commit d1c947c

Browse files
committed
Initial commit
0 parents  commit d1c947c

File tree

18 files changed

+499
-0
lines changed

18 files changed

+499
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.conf
2+
*.pem
3+
*.key
4+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Alan Williams
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Ansible Playbook for Splunk
2+
==============
3+
4+
This Ansible playbook installs and configures a Splunk 6.1 cluster
5+
6+
7+
So far I've only used and tested this playbook on AWS instances.
8+
9+
* The [core](https://github.com/alanwill/cfn-core) CloudFormation template is used to create the VPC
10+
* The [cfn-splunk](https://github.com/alanwill/cfn-splunk) CloudFormation template is used to create the Splunk components
11+
12+
You don't have to use the above templates and can surely use a pre-created VPC and instances, just be sure that your instances are tagged as Ansible expects or tweak the splunk-site.yml file to adapt to your tagging convention.
13+
14+
This playbook will do the following:
15+
16+
* Install the latest OS security updates on all instances
17+
* Update the hostsnames on all instances to be the EC2 instance ID
18+
* Download and install the Splunk Enterprise RPM on all instances, if it's not already installed
19+
* Delete the RPM after successful install
20+
* Run config_splunk_inputs.sh which updates the inputs.conf on each component to include the instance hostname
21+
* Start Splunk and set to auto-start on boot
22+
* Update ACLs to allow Splunk to read /var/log files
23+
* Reset the default Splunk password
24+
* Copy custom configuration files (authentication.conf, web.conf, authorize.conf, ui-prefs.conf, alert_actions.conf)
25+
* Copy custom certs for Splunk Web
26+
* Add nodes to the License Master
27+
* Restart Splunk
28+
* Install packages to enable Cloudwatch metrics
29+
* Configure the Cluster Master with a replication factor of 3 and search factor of 2 then restart Splunk on the instance
30+
* Add the Search Heads to the cluster, then restart Splunk on them
31+
* Add the Peer Nodes to the cluster
32+
* Partition and mount the Peer node volumes
33+
* Disable Splunk web on the Peer Nodes
34+
35+
By the time this playbook completes you'll have a working Splunk cluster.
36+
37+
##Future
38+
39+
There's a few things I'm looking to do to make this playbook more re-usable, namely:
40+
41+
* Increase the idempotency
42+
* Make the peer node role more dynamic to various instance sizes. As it, it works best with i2.2xlarge instances
43+
* Consolidate all variables to a single master file
44+
45+
##Contributing
46+
47+
I can't say this enough, Pull Requests are very much welcomed. Hope this playbook helps others as much as it helps me. If you have any feedback on ways to improve it, I'm all ears. Submit an Issue if something doesn't work as advertised.
48+
49+
alan
50+
51+
52+
53+
54+

roles/cluster-master/tasks/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
# This role contains plays to install and configure the Cluster Master
3+
4+
- name: Check if clustering is enabled
5+
command: runuser -l splunk -c "/opt/splunk/bin/splunk list cluster-peers -auth admin:{{ new_pass }}"
6+
register: cluster_master_clustering_enabled
7+
ignore_errors: True
8+
9+
- name: Enable Cluster Master
10+
command: runuser -l splunk -c "splunk edit cluster-config -mode master -replication_factor 3 -search_factor 2 -secret {{ replication_key }}"
11+
when: cluster_master_clustering_enabled|failed
12+
register: cluster_master_configure
13+
14+
- name: Restart Cluster Master
15+
command: runuser -l splunk -c "splunk restart"
16+
when: cluster_master_clustering_enabled|failed

roles/common/tasks/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# This role contains common plays that will run on all nodes.
3+
4+
- name: upgrade all packages
5+
yum: name=* state=latest
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
# This role contains plays to configure the Deployment Server
3+

roles/license-master/tasks/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
# This role contains plays to configure the License Master
3+
4+
- name: Create license folder
5+
file: path=/opt/splunk/licenses state=directory owner=splunk group=splunk mode=744
6+
7+
- name: Download license key from S3
8+
s3: bucket={{ splunk-config-bucket }} object=/licenses/splunk.license dest=/opt/splunk/licenses/splunk.license mode=get
9+
10+
- name: Install license key
11+
command: runuser -l splunk -c "/opt/splunk/bin/splunk add licenses /opt/splunk/licenses/splunk.license"
12+
ignore_errors: True
13+
14+
- name: Restart Splunk
15+
command: runuser -l splunk -c "splunk restart"
16+

roles/license-master/vars/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
# S3 bucket name containing Splunk licenses and configs
3+
splunk-config-bucket:

roles/peer-nodes/tasks/main.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
# This role contains plays to install and configure the Peer Nodes
3+
4+
- name: Check if clustering is enabled
5+
command: runuser -l splunk -c "/opt/splunk/bin/splunk list cluster-peers -auth admin:{{ new_pass }}"
6+
register: peer_nodes_clustering_enabled
7+
ignore_errors: True
8+
9+
- name: Enable Peer Nodes
10+
command: runuser -l splunk -c "splunk edit cluster-config -mode slave -master_uri https://{{ splunk_cluster_master_ip }}:8089 -replication_port 9887 -secret {{ replication_key }}"
11+
when: peer_nodes_clustering_enabled|failed
12+
register: peer_nodes_cluster_configure
13+
14+
- name: Check if Splunk data volume exists
15+
mount: name=/opt/splunk/data src=/dev/md127 fstype=ext4 state=mounted
16+
register: splunk_volume_exists
17+
ignore_errors: True
18+
19+
- name: Gather EC2 facts
20+
action: ec2_facts
21+
22+
#- name: Prewarm EBS volume1
23+
# command: dd if=/dev/zero of=/dev/sdf bs=1M
24+
# when: splunk_volume_exists|failed
25+
# ignore_errors: True
26+
27+
#- name: Prewarm EBS volume2
28+
# command: dd if=/dev/zero of=/dev/sdg bs=1M
29+
# when: splunk_volume_exists|failed
30+
# ignore_errors: True
31+
32+
- name: Partition 90% of disk0 for use
33+
shell: (echo n; echo p; echo 1; echo 2048; echo +720G; echo w) | fdisk /dev/xvdb
34+
when: splunk_volume_exists|failed
35+
36+
- name: Partition 90% of disk1 for use
37+
shell: (echo n; echo p; echo 1; echo 2048; echo +720G; echo w) | fdisk /dev/xvdc
38+
when: splunk_volume_exists|failed
39+
40+
- name: Create RAID 0 device
41+
command: mdadm --create --verbose /dev/md127 --level=stripe --raid-devices=2 /dev/xvdb1 /dev/xvdc1
42+
when: splunk_volume_exists|failed
43+
44+
- name: Create filesystem
45+
filesystem: fstype=ext4 dev=/dev/md127
46+
when: splunk_volume_exists|failed
47+
48+
- name: Create data directory
49+
command: runuser -l splunk -c "mkdir -p /opt/splunk/data"
50+
when: splunk_volume_exists|failed
51+
52+
- name: Mount volume
53+
mount: name=/opt/splunk/data src=/dev/md127 fstype=ext4 state=mounted
54+
when: splunk_volume_exists|failed
55+
56+
- name: Set default data store
57+
command: runuser -l splunk -c "splunk set datastore-dir /opt/splunk/data -auth admin:{{ new_pass }}"
58+
59+
- name: Change permissions of data mount point
60+
command: chown -R splunk.splunk /opt/splunk/data
61+
62+
- name: Disable splunkweb
63+
command: runuser -l splunk -c "splunk disable webserver -auth admin:{{ new_pass }}"
64+
65+
- name: Restart Peer Nodes
66+
command: runuser -l splunk -c "splunk restart"
67+
when: peer_nodes_cluster_configure|success

roles/peer-nodes/vars/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
# IP address of the cluster master
3+
splunk_cluster_master_ip:

0 commit comments

Comments
 (0)