Skip to content

Commit

Permalink
Fixes #8: Complete rewrite for modern Solr installation.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Mar 28, 2015
1 parent 68e1f56 commit bfcfb80
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 127 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ script:
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Make sure Java is installed.
- >
curl http://localhost:8080/solr/core0/admin/ping
# Make sure Solr is running.
- curl http://localhost:8080/solr/core0/admin/ping
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,63 @@

[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-solr.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-solr)

An Ansible Role that installs Apache Solr (running under Tomcat 6) on RedHat/CentOS 6.x and Debian/Ubuntu Linux servers.
An Ansible Role that installs Apache Solr on Linux servers.

## Requirements

None.
Java must be available on the server. You can easily install Java using the `geerlingguy.java` role.

This role is currently tested and working with Solr 3.x and 4.x; 5.x is not yet fully tested.

## Role Variables

Available variables are listed below, along with default values (see `vars/main.yml`):

workspace: /root
solr_workspace: /root

Files will be downloaded to this path on the remote server before being moved into place.

solr_version: "4.9.0"
solr_create_user: true
solr_user: solr

Solr will be run under Jetty as the `solr_user`. Set `solr_create_user` to `false` if `solr_user` is created before this role runs.

solr_version: "4.10.4"

The Apache Solr version to install.

solr_path: /opt/solr
solr_install_path: /opt/solr

The path where Apache Solr will be installed.

solr_home: /var/solr

The path where local Solr data (search collections and configuration) will be stored. Should typically be outside of the `solr_path`, to make Solr upgrades easier.

solr_log_file_path: /var/log/solr.log

Path where Solr log file will be created.

solr_port: "8983"

The port on which Solr will run.

solr_xms: "256M"
solr_xmx: "512M"

Memory settings for the JVM. These should be set as high as you can allow for best performance and to reduce the chance of Solr restarting itself due to OOM situations.

## Dependencies

- geerlingguy.tomcat6 (Installs Tomcat 6).
None.

## Example Playbook

- hosts: solrserver
- hosts: solr-servers
roles:
- { role: geerlingguy.java }
- { role: geerlingguy.solr }

## TODO

- Set up better scaffolding for each core.
- Allow for more advanced configuration (multi-server, master, slave, etc.).

## License

MIT / BSD
Expand Down
26 changes: 14 additions & 12 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
workspace: /root
tomcat_user: tomcat
tomcat_lib_path: /usr/share/tomcat6/lib/
solr_version: "4.10.2"
solr_path: /opt/solr

# The first core in the list will be set as the default Solr core. For now, this
# list is hardcoded here and shouldn't be overridden unless you know what you're
# doing. Someday, this will be more easily configurable.
solr_cores:
- core0
- core1
solr_workspace: /root

solr_create_user: true
solr_user: solr

solr_version: "4.10.4"

solr_install_path: /opt/solr
solr_home: /var/solr
solr_log_file_path: /var/log/solr.log

solr_port: "8983"
solr_xms: "256M"
solr_xmx: "512M"
Binary file removed files/cores.tar.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart solr
service: name=solr state=restarted
5 changes: 2 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
dependencies:
- { role: geerlingguy.tomcat6 }
dependencies: []

galaxy_info:
author: geerlingguy
description: Apache Solr for RHEL/CentOS and Debian/Ubuntu.
description: Apache Solr for Linux.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 1.4
Expand Down
23 changes: 23 additions & 0 deletions tasks/init.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Ensure log file is created and has proper permissions.
file:
path: "/var/log/solr.log"
state: touch
owner: "{{ solr_user }}"
group: root
mode: 0664
changed_when: false

- name: Copy solr init script into place.
template:
src: "solr-init-{{ ansible_os_family }}.j2"
dest: /etc/init.d/solr
mode: 0755
notify: restart solr

- name: Ensure daemon is installed (Debian).
apt: name=daemon state=installed
when: ansible_os_family == "Debian"

- name: Ensure solr is started and enabled on boot.
service: name=solr state=started enabled=yes
101 changes: 24 additions & 77 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,39 @@
---
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
- include: user.yml
when: solr_create_user

- name: Set solr_filename for Solr 4.x.
set_fact: >
solr_filename=solr-{{ solr_version }}
set_fact:
"solr_filename=solr-{{ solr_version }}"
when: "solr_version.split('.')[0] == '4'"

- name: Set solr_filename for Solr 3.x.
set_fact: >
solr_filename=apache-solr-{{ solr_version }}
set_fact:
solr_filename: "apache-solr-{{ solr_version }}"
when: "solr_version.split('.')[0] == '3'"

- name: Download Solr.
get_url: >
url=http://archive.apache.org/dist/lucene/solr/{{ solr_version }}/{{ solr_filename }}.tgz
dest={{ workspace }}/{{ solr_filename }}.tgz
force=no
get_url:
url: "http://archive.apache.org/dist/lucene/solr/{{ solr_version }}/{{ solr_filename }}.tgz"
dest: "{{ solr_workspace }}/{{ solr_filename }}.tgz"
force: no

- name: Expand Solr.
command: >
tar -C {{ workspace }} -xvzf {{ workspace }}/{{ solr_filename }}.tgz
creates={{ workspace }}/{{ solr_filename }}/dist/{{ solr_filename }}.war
tar -C {{ solr_workspace }} -xvzf {{ solr_workspace }}/{{ solr_filename }}.tgz
creates={{ solr_workspace }}/{{ solr_filename }}/dist/{{ solr_filename }}.war
- name: Copy Solr into place.
command: >
cp -r {{ workspace }}/{{ solr_filename }} {{ solr_path }}
creates={{ solr_path }}/dist/{{ solr_filename }}.war
- name: Copy Solr war file into place.
command: >
cp {{ solr_path }}/dist/{{ solr_filename }}.war {{ solr_path }}/solr.war
creates={{ solr_path }}/solr.war
notify: restart tomcat

- name: Copy solr.xml into Tomcat.
template: >
src=Catalina/solr.xml.j2
dest=/etc/tomcat6/Catalina/{{ tomcat6_hostname }}/solr.xml
owner={{ tomcat_user }} group={{ tomcat_user }} mode=755
notify: restart tomcat

- name: Copy Solr multicore example into place.
command: >
cp -R {{ solr_path }}/example/multicore {{ solr_path }}/cores
creates={{ solr_path }}/cores/README.txt
notify: restart tomcat

- name: Check if solr.xml file already exists.
stat: "path={{ solr_path }}/solr.xml"
register: solr_file

- name: Copy Solr core XML file into place.
template: >
src=solr.xml.j2
dest={{ solr_path }}/solr.xml
owner={{ tomcat_user }}
group={{ tomcat_user }}
mode=755
backup=yes
when: solr_file.stat.exists == false
notify: restart tomcat

- name: Check if setup-complete file exists.
stat: "path={{ solr_path }}/setup-complete"
register: setup_complete

- name: Copy logging jar files and configuration into place for Solr 4.x.
shell: "{{ item }}"
with_items:
- "cp -n {{ solr_path }}/example/lib/ext/* {{ tomcat_lib_path }}"
- "cp -n {{ solr_path }}/example/resources/log4j.properties {{ tomcat_lib_path }}"
when: "(setup_complete.stat.exists == false) and (solr_version.split('.')[0] == '4')"
notify: restart tomcat

- name: Fix file permissions.
file: >
path={{ solr_path }}
state=directory
owner={{ tomcat_user }} group={{ tomcat_user }} mode=0755
recurse=yes
when: setup_complete.stat.exists == false

- name: Create file to indicate Solr install completion.
file: >
path={{ solr_path }}/setup-complete
state=touch
owner={{ tomcat_user }}
group={{ tomcat_user }}
mode=755
when: setup_complete.stat.exists == false
cp -r {{ solr_workspace }}/{{ solr_filename }} {{ solr_install_path }}
creates={{ solr_install_path }}/dist/{{ solr_filename }}.war
- name: Ensure Solr install files are owned by the solr_user.
file:
path: "{{ solr_install_path }}"
owner: "{{ solr_user }}"
group: "{{ solr_user }}"
recurse: yes

- include: solr-home.yml
- include: init.yml
30 changes: 30 additions & 0 deletions tasks/solr-home.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Ensure solr_home directory exists.
file:
path: "{{ solr_home }}"
state: directory
owner: "{{ solr_user }}"
group: "{{ solr_user }}"
mode: 0755

- name: Check if solr_home is already set up.
stat: "path={{ solr_home }}/solr.xml"
register: solr_example

- name: Copy Solr example into solr_home.
shell: "cp -r {{ solr_install_path }}/example/solr/* {{ solr_home }}"
when: not solr_example.stat.exists

- name: Fix the example solrconfig.xml file.
replace:
dest: "{{ solr_home }}/collection1/conf/solrconfig.xml"
regexp: ^.+solr\.install\.dir.+$
replace: ""
when: "not solr_example.stat.exists and solr_version.split('.')[0] == '3'"

- name: Ensure Solr home files are owned by the solr_user.
file:
path: "{{ solr_home }}"
owner: "{{ solr_user }}"
group: "{{ solr_user }}"
recurse: yes
9 changes: 9 additions & 0 deletions tasks/user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Ensure solr_user group exists.
group: "name={{ solr_user }} state=present"

- name: Ensure solr_user exists.
user:
name: "{{ solr_user }}"
state: present
group: "{{ solr_user }}"
3 changes: 0 additions & 3 deletions templates/Catalina/solr.xml.j2

This file was deleted.

Loading

0 comments on commit bfcfb80

Please sign in to comment.