Skip to content

Commit db62074

Browse files
committed
install app from a local folder, pull splunk#81
1 parent d29b887 commit db62074

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ansible-role-for-splunk is used by the Splunk@Splunk team to manage Splunk's cor
2323
## Purpose
2424

2525
#### What is ansible-role-for-splunk?
26-
ansible-role-for-splunk is a single Ansible role for deploying and administering production Splunk deployments. It supports all Splunk deployment roles (Universal Forwarder, Heavy Forwarder, Indexer, Search Head, Deployment Server, Cluster Master, SHC Deployer, DMC, License Master) as well as management of all apps and configurations (via git repositories).
26+
ansible-role-for-splunk is a single Ansible role for deploying and administering production Splunk deployments. It supports all Splunk deployment roles (Universal Forwarder, Heavy Forwarder, Indexer, Search Head, Deployment Server, Cluster Master, SHC Deployer, DMC, License Master) as well as management of all apps and configurations (via git repositories or local folder).
2727

2828
This codebase is used by the Splunk@Splunk team internally to manage our deployment, so it has been thoroughly vetted since it was first developed in late 2018. For more information about Ansible best practices, checkout [our related .conf20 session](https://conf.splunk.com/learn/session-catalog.html?search=TRU1537C) for this project.
2929

@@ -92,6 +92,14 @@ git_apps:
9292
- name: my_app
9393
version: master
9494
```
95+
or you will need to configure the `local_apps` & `local_apps_path` variables:
96+
```
97+
local_apps:
98+
- name: my_app
99+
- name: my_second_app
100+
local_apps_path: ~/path_on_my_ansible_host/to_the_apps
101+
```
102+
95103
You will find additional examples in the included sample [group_vars](https://github.com/splunk/ansible-role-for-splunk/blob/master/environments/production/group_vars/deploymentserver.yml) and [host_vars](https://github.com/splunk/ansible-role-for-splunk/blob/master/environments/production/host_vars/my-shc-deployer.yml) files. Note that you may also specify `git_server`, `git_key`, `git_project`, and `git_version` within `git_apps` down to the repository (`name`) level.
96104
You may also override the auto-configured `splunk_app_deploy_path` at the repository level as well. For example, to deploy apps to $SPLUNK_HOME/etc/apps on a deployment server rather than the default of $SPLUNK_HOME/etc/deployment-apps. If not set, configure_apps.yml will determine the app deployment path based on the host's group membership within the inventory.
97105
**Tip:** If you only use one git server, you may want to define the `git_server` and related values in an all.yml group_var file.
@@ -133,7 +141,7 @@ Note: Any task with an **adhoc** prefix means that it can be used independently
133141
- **adhoc_kill_splunkd.yml** - Some releases of Splunk have a "feature" that leaves zombie splunkd processes after a 'splunk stop'. Use this task after a 'splunk stop' to make sure that it's really stopped. Useful for upgrades on some of the 7.x releases, and automatically called by the upgrade_splunk.yml task.
134142
- **check_splunk.yml** - Check if Splunk is installed. If Splunk is not installed, it will be installed on the host. If Splunk is already installed, the task will execute a "splunk version" command on the host, and then compare the version and build number of Splunk to the version and build number of the expected version of Splunk. Note that the expected version of Splunk does not need to be statically defined; The expected Splunk version and build are automatically extracted from the value of splunk_package_url_full or splunk_package_url_uf using Jinja regex filters. This task will work for both the Universal Forwarder and full Splunk Enterprise packages. You define which host uses what package by organizing it under the appropriate group ('full' or 'uf') in your Ansible inventory.
135143
- **check_decrypted_secret.yml** - Check the decrypted value of a given `pass4SymmKey`. This can be called by a task to compare the desired value with the currently configured value to see if they match. This pervents unnessecary changes to be applied.
136-
- **configure_apps.yml** - This task should be called directly from a playbook in order to deploy apps or configurations (from git repositories) to Splunk hosts. Tip: Add a this task to a playbook after the check_splunk.yml play. Doing so will perform a "install (or upgrade) and deploy apps" run, all in one playbook.
144+
- **configure_apps.yml** - This task should be called directly from a playbook in order to deploy apps or configurations (from git repositories or local folder) to Splunk hosts. Tip: Add a this task to a playbook after the check_splunk.yml play. Doing so will perform a "install (or upgrade) and deploy apps" run, all in one playbook.
137145
- **configure_auditd.yml** - Configure auditd filtering rules to exclude splunk launched executables. Disabled by default, but can be enabled by setting `splunk_auditd_configure` to `true`.
138146
- **configure_authentication.yml** - Uses the template identified by the `splunk_authenticationconf` variable to install an authentication.conf file to $SPLUNK_HOME/etc/system/local/authentication.conf. We are including this task here since Ansible is able to securely deploy an authentication.conf configuration by using ansible-vault to encrypt sensitive values such as the value of the `ad_bind_password` variable. Note: If you are using a common splunk.secret file, you can omit this task and instead use configure_apps.yml to deploy an authentication.conf file from a Git repository containing an authentication.conf app with pre-hashed credentials.
139147
- **configure_bash.yml** - Configures bashrc and bash_profile files for the splunk user. Please note that the templates included with this role will overwrite any existing files for the splunk user (if they exist). The templates will define a custom PS1 at the bash prompt, configure the $SPLUNK_HOME environment variable so that you can issue "splunk <command>" without specifying the full path to the Splunk binary, and will enable auto-completion of Splunk CLI commands in bash.

environments/development/group_vars/all.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ ansible_user: my_ansible_ssh_user
44
ansible_ssh_private_key_file: ~/.ssh/my_ansible_ssh.key
55
git_server: ssh://git@mygithost:1234
66
git_key: ~/.ssh/my-git-key
7+
local_apps:
8+
- my_app
9+
- my_second_app
10+
local_apps_path: ~/workdir/

roles/splunk/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ systemd_unit_uf: SplunkForwarder # You can change this in `host_vars` or `group_
4545
splunk_disable_mgmt_port: false # If set to true, will disable splunkd management port during installation
4646
splunk_mgmt_uri: "{{ ansible_fqdn }}" # If the `ansible_fqdn` is not resolvable by other hosts, you can set it to something like `ansible_facts.default_ipv4.address` in `host_vars` or `group_vars` to use the IP address instead.
4747
splunkd_port: 8089 # If changed, will overwrite the default port number used by splunkd
48+
local_apps_path: undefined
4849
git_local_clone_path: ~/ # Base directory under which repositories for app deplyoment should be cloned to
4950
git_server: undefined # e.g. ssh://git@mygithost:1234 - Note that this may be set in an all.yml group_var or inside the git_apps dictionary within host_vars
5051
git_key: undefined # Path to SSH key for cloning repositories - Note that this may be set in an all.yml group_var or inside the git_apps dictionary within host_vars

roles/splunk/tasks/configure_apps.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,45 @@
9494
- git_key != 'undefined'
9595
- git_server != 'undefined'
9696
- git_project != 'undefined'
97+
98+
# Prepare the Ansible host to deploy apps then install them
99+
- block:
100+
- name: Install .rsync-filter to avoid copying undesirable files and folders to the target host later
101+
copy:
102+
src: rsync-filter
103+
dest: "{{ local_apps_path }}/.rsync-filter"
104+
delegate_to: localhost
105+
changed_when: false
106+
107+
- name: Ensure rsync is installed on target host
108+
package:
109+
name: rsync
110+
state: present
111+
update_cache: true
112+
become: true
113+
114+
- name: "Comment out requiretty in sudoers as it causes synchronize to fail on target host"
115+
lineinfile:
116+
dest: "/etc/sudoers"
117+
state: present
118+
regexp: "^#?{{ item }}"
119+
line: "#{{ item }}"
120+
create: true
121+
owner: root
122+
group: root
123+
mode: 0440
124+
loop:
125+
- "Defaults requiretty"
126+
become: true
127+
128+
- name: Install apps
129+
include_tasks: install_apps.yml
130+
loop: "{{ local_apps }}"
131+
vars:
132+
app_dest: "{{ item.splunk_app_deploy_path | default(splunk_app_deploy_path) }}"
133+
app_src: "{{ local_apps_path }}/{{ item.name }}"
134+
135+
# Conditional for block
136+
when:
137+
- local_apps is defined
138+
- local_apps_path is defined

0 commit comments

Comments
 (0)