use YAML dictionaries for ansible tasks

parent 0a993c8d
...@@ -17,4 +17,6 @@ ...@@ -17,4 +17,6 @@
# Restart Splunk # Restart Splunk
- name: restart splunkforwarder - name: restart splunkforwarder
service: name=splunk state=restarted service:
name: splunk
state: restarted
...@@ -22,83 +22,90 @@ ...@@ -22,83 +22,90 @@
# #
# Install Splunk Forwarder # Install Splunk Forwarder
- name: install splunkforwarder specific system packages - name: Install splunkforwarder specific system packages
apt: pkg={{','.join(splunk_debian_pkgs)}} state=present apt:
name: "{{ item }}"
state: present
with_items: "{{ splunk_debian_pkgs }}"
tags: tags:
- splunk - splunk
- install - install
- update - update
- name: download the splunk deb - name: Download the splunk deb
get_url: > get_url:
dest="/tmp/{{ SPLUNKFORWARDER_DEB }}" dest: "/tmp/{{ SPLUNKFORWARDER_DEB }}"
url="{{ SPLUNKFORWARDER_PACKAGE_URL }}" url: "{{ SPLUNKFORWARDER_PACKAGE_URL }}"
register: download_deb register: download_deb
- name: install splunk forwarder - name: Install splunk forwarder
shell: gdebi -nq /tmp/{{ SPLUNKFORWARDER_DEB }} shell: "gdebi -nq /tmp/{{ SPLUNKFORWARDER_DEB }}"
when: download_deb.changed when: download_deb.changed
# Create splunk user - name: Create splunk user
- name: create splunk user user:
user: name=splunk createhome=no state=present append=yes groups=syslog,adm name: splunk
createhome: no
state: present
append: yes
groups: syslog,adm
when: download_deb.changed when: download_deb.changed
# Need to start splunk manually so that it can create various files # Need to start splunk manually so that it can create various files
# and directories that aren't created till the first run and are needed # and directories that aren't created till the first run and are needed
# to run some of the below commands. # to run some of the below commands.
- name: start splunk manually - name: Start splunk manually
shell: > shell: "{{ splunkforwarder_output_dir }}/bin/splunk start --accept-license --answer-yes --no-prompt"
{{ splunkforwarder_output_dir }}/bin/splunk start --accept-license --answer-yes --no-prompt args:
creates={{ splunkforwarder_output_dir }}/var/lib/splunk creates: "{{ splunkforwarder_output_dir }}/var/lib/splunk"
when: download_deb.changed when: download_deb.changed
register: started_manually register: started_manually
- name: stop splunk manually - name: Stop splunk manually
shell: > shell: "{{ splunkforwarder_output_dir }}/bin/splunk stop --accept-license --answer-yes --no-prompt"
{{ splunkforwarder_output_dir }}/bin/splunk stop --accept-license --answer-yes --no-prompt
when: download_deb.changed and started_manually.changed when: download_deb.changed and started_manually.changed
- name: create boot script - name: Create boot script
shell: > shell: "{{ splunkforwarder_output_dir }}/bin/splunk enable boot-start -user splunk --accept-license --answer-yes --no-prompt"
{{ splunkforwarder_output_dir }}/bin/splunk enable boot-start -user splunk --accept-license --answer-yes --no-prompt args:
creates=/etc/init.d/splunk creates: /etc/init.d/splunk
register: create_boot_script register: create_boot_script
when: download_deb.changed when: download_deb.changed
notify: restart splunkforwarder notify: restart splunkforwarder
# Ensure permissions on splunk content - name: Ensure splunk forder permissions
- name: ensure splunk forder permissions file:
file: path={{ splunkforwarder_output_dir }} state=directory recurse=yes owner=splunk group=splunk path: "{{ splunkforwarder_output_dir }}"
state: directory
recurse: yes
owner: splunk
group: splunk
when: download_deb.changed when: download_deb.changed
notify: restart splunkforwarder notify: restart splunkforwarder
# Update credentials - name: Update admin pasword
- name: update admin pasword
shell: "{{ splunkforwarder_output_dir }}/bin/splunk edit user admin -password {{ SPLUNKFORWARDER_PASSWORD }} -auth admin:changeme --accept-license --answer-yes --no-prompt" shell: "{{ splunkforwarder_output_dir }}/bin/splunk edit user admin -password {{ SPLUNKFORWARDER_PASSWORD }} -auth admin:changeme --accept-license --answer-yes --no-prompt"
when: download_deb.changed when: download_deb.changed
notify: restart splunkforwarder notify: restart splunkforwarder
- name: add chkconfig to init script - name: Add chkconfig to init script
shell: 'sed -i -e "s/\/bin\/sh/\/bin\/sh\n# chkconfig: 235 98 55/" /etc/init.d/splunk' lineinfile:
dest: /etc/init.d/splunk
regexp: "^# chkconfig: 235 98 55"
line: "# chkconfig: 235 98 55"
insertafter: "#!/bin/sh"
state: present
when: download_deb.changed and create_boot_script.changed when: download_deb.changed and create_boot_script.changed
notify: restart splunkforwarder notify: restart splunkforwarder
# Drop template files. - name: Create inputs and outputs configuration
- name: drop input configuration
template: template:
src=opt/splunkforwarder/etc/system/local/inputs.conf.j2 src: "opt/splunkforwarder/etc/system/local/{{ item }}.conf.j2"
dest=/opt/splunkforwarder/etc/system/local/inputs.conf dest: "/opt/splunkforwarder/etc/system/local/{{ item }}.conf"
owner=splunk owner: splunk
group=splunk group: splunk
mode=644 mode: 644
notify: restart splunkforwarder with_items:
- inputs
- name: create outputs config file - outputs
template: notify: restart splunkforwarder
src=opt/splunkforwarder/etc/system/local/outputs.conf.j2 \ No newline at end of file
dest=/opt/splunkforwarder/etc/system/local/outputs.conf
owner=splunk
group=splunk
mode=644
notify: restart splunkforwarder
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment