Skip to main content

Install and setup Apache SOLR v.4+ for Drupal, using Ansible

Drupal ver.: 
Apache SOLR

Hi, in this article I’ll try to write a guide about how to install Apache Solr & setup it with Drupal configs from scratch. I’m going to reuse existing opensource solutions to avoid manual code writing in the console and automate this routine in case when anyone want to do the same.

So the first thing that we need it’s Ansible - the simplest way to automate our work.

We are going to use the latest Ansible version and installation script that might look like:

#! /bin/bash
# Only install if not exists
if [ ! -x /usr/bin/ansible ]; then
  echo ">>> Installing ansible";
  apt-get update
  apt-get install python-pip python-dev git -y
  pip install PyYAML jinja2 paramiko
  git clone
  cd ansible
  # fix error
  git submodule update --init --recursive
  make install
  mkdir /etc/ansible
  cp ~/ansible/examples/hosts /etc/ansible/
  ln -s /root/ansible/bin/ansible /usr/bin/ansible

I assume that Ansible should be installed to the root folder in this script, but feel free to change it up to your requirements.

Next one: we'll use this great ansible-multicore-solr role to install all the stuff and even setup solr too!

$ cd ~
$ git clone 
$ cd ansible-multicore-solr

Next one: we'll override role variables like: solr version, drupal integration module, solar cores list.

$ mkdir group_vars
$ nano group_vars/solr

And put them here:

jiv_solr__version: 4.10.2
jiv_solr__searchApiSolrVersion: 7.x-1.6
  # Just for example
  - { name: core1, coreType: default, keepChanges: no }
  # Just for example
  - { name: core2, coreType: drupal_apachesolr, keepChanges: no }
  - { name: abcmoda, coreType: drupal_search_api_solr, keepChanges: no }

Continue, apply our config overrides to the current host:

$ nano hosts

And add this:


Finally we are going to run Ansible and let it do all the stuff:

$ ansible-playbook -i hosts play.yml -c local
$ ansible-playbook -i hosts play.yml -c local -e jiv_solr__uninstall=1

Go to Drupal website, navigate to the admin/config/search/search_api/server/[YOUR_SERVER_ID]/edit and add Solr path parameter:


Summarizing we could short this to the:

$ cd ~ && wget
$ sh
$ git clone 
$ cd ansible-multicore-solr
$ mkdir group_vars
$ wget -O group_vars/solr
# Add your overrides
$ nano hosts
$ ansible-playbook -i hosts play.yml -c local

Bonus: you can store search API server settings config in the settings.php.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.