Apache Solr is a fast and scalable search server optimized for full-text search, word highlighting, faceted search, fast indexing, and more. It’s a very popular search server, and it’s pretty easy to install and configure using Ansible.

Step 1. Getting roles from Galaxy
https://galaxy.ansible.com/
ansible-galaxy install geerlingguy.java geerlingguy.solr
Step 2. create solr.yml
---
- hosts: all
become: yes
roles:
- geerlingguy.java
- geerlingguy.solr
---
- hosts: all
become: yes
roles:
- geerlingguy.java
- geerlingguy.solr
--- - hosts: all become: yes roles: - geerlingguy.java - geerlingguy.solr
Step 3. run it with ansible-playbook solr.yml, then you can open http://ubuntu2004:8983/solr

if you didn’t install roles, the playbook.yml could be:
---
- hosts: all
become: true
vars_files:
- vars.yml
pre_tasks:
- name: Update apt cache if needed.
apt: update_cache=true cache_valid_time=3600
tasks:
- name: Install Java.
apt: name=openjdk-11-jdk state=present
- name: Download Solr.
get_url:
url: "https://archive.apache.org/dist/lucene/solr/{{ solr_version }}/solr-{{ solr_version }}.tgz"
dest: "{{ download_dir }}/solr-{{ solr_version }}.tgz"
checksum: "{{ solr_checksum }}"
- name: Expand Solr.
unarchive:
src: "{{ download_dir }}/solr-{{ solr_version }}.tgz"
dest: "{{ download_dir }}"
remote_src: true
creates: "{{ download_dir }}/solr-{{ solr_version }}/README.txt"
- name: Run Solr installation script.
command: >
{{ download_dir }}/solr-{{ solr_version }}/bin/install_solr_service.sh
{{ download_dir }}/solr-{{ solr_version }}.tgz
-i /opt
-d /var/solr
-u solr
-s solr
-p 8983
creates={{ solr_dir }}/bin/solr
- name: Ensure solr is started and enabled on boot.
service: name=solr state=started enabled=yes
---
- hosts: all
become: true
vars_files:
- vars.yml
pre_tasks:
- name: Update apt cache if needed.
apt: update_cache=true cache_valid_time=3600
tasks:
- name: Install Java.
apt: name=openjdk-11-jdk state=present
- name: Download Solr.
get_url:
url: "https://archive.apache.org/dist/lucene/solr/{{ solr_version }}/solr-{{ solr_version }}.tgz"
dest: "{{ download_dir }}/solr-{{ solr_version }}.tgz"
checksum: "{{ solr_checksum }}"
- name: Expand Solr.
unarchive:
src: "{{ download_dir }}/solr-{{ solr_version }}.tgz"
dest: "{{ download_dir }}"
remote_src: true
creates: "{{ download_dir }}/solr-{{ solr_version }}/README.txt"
- name: Run Solr installation script.
command: >
{{ download_dir }}/solr-{{ solr_version }}/bin/install_solr_service.sh
{{ download_dir }}/solr-{{ solr_version }}.tgz
-i /opt
-d /var/solr
-u solr
-s solr
-p 8983
creates={{ solr_dir }}/bin/solr
- name: Ensure solr is started and enabled on boot.
service: name=solr state=started enabled=yes
--- - hosts: all become: true vars_files: - vars.yml pre_tasks: - name: Update apt cache if needed. apt: update_cache=true cache_valid_time=3600 tasks: - name: Install Java. apt: name=openjdk-11-jdk state=present - name: Download Solr. get_url: url: "https://archive.apache.org/dist/lucene/solr/{{ solr_version }}/solr-{{ solr_version }}.tgz" dest: "{{ download_dir }}/solr-{{ solr_version }}.tgz" checksum: "{{ solr_checksum }}" - name: Expand Solr. unarchive: src: "{{ download_dir }}/solr-{{ solr_version }}.tgz" dest: "{{ download_dir }}" remote_src: true creates: "{{ download_dir }}/solr-{{ solr_version }}/README.txt" - name: Run Solr installation script. command: > {{ download_dir }}/solr-{{ solr_version }}/bin/install_solr_service.sh {{ download_dir }}/solr-{{ solr_version }}.tgz -i /opt -d /var/solr -u solr -s solr -p 8983 creates={{ solr_dir }}/bin/solr - name: Ensure solr is started and enabled on boot. service: name=solr state=started enabled=yes
Helpful Galaxy commands:
ansible-galaxy list displays a list of installed roles, with version numbers
ansible-galaxy remove [role] removes an installed role
I want to point out my affection for your generosity for those who actually need guidance on this important issue. Your very own commitment to getting the solution around has been unbelievably important and have truly enabled folks just like me to reach their aims. Your own helpful hints and tips means so much a person like me and extremely more to my office workers. Regards; from each one of us.