Skip to content

Commit

Permalink
Install ES
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunBoughey committed Aug 13, 2022
0 parents commit 0cb2943
Show file tree
Hide file tree
Showing 16 changed files with 341 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
language: python
python: "2.7"

# Use the new container infrastructure
sudo: false

# Install ansible
addons:
apt:
packages:
- python-pip

install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
33 changes: 33 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# Based on ansible-lint config
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Elasticsearch
=========

An Elasticsearch role that can deploy a standalone node or a cluster. All tested with molecule.

Requirements
------------

No requirements for this role.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

No dependencies for this role.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: elastic
roles:
- pictowolf.elasticsearch

8 changes: 8 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# defaults file for elasticsearch
es_major_version: 7
es_minor_version: 15.2-1

es_cluster_name: dev-cluster
es_data_path: /data/elasticsearch
es_log_path: /var/log/elasticsearch
2 changes: 2 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for elasticsearch
52 changes: 52 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:
author: pictowolf
namespace: pictowolf
description: Installs elasticsearch either as a standalone node or clustered.
company: Infinity Servers

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: MIT
min_ansible_version: "2.1"

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: EL
versions:
- all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
7 changes: 7 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include pictowolf.elasticsearch"
include_role:
name: "pictowolf.elasticsearch"
22 changes: 22 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
dependency:
name: galaxy
driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint .
platforms:
- name: instance1
image: "geerlingguy/docker-centos7-ansible:latest"
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
groups:
- master
provisioner:
name: ansible
verifier:
name: ansible
10 changes: 10 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
ansible.builtin.assert:
that: true
5 changes: 5 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Set elasticsearch.yml
ansible.builtin.template:
src: elasticsearch.yml.j2
dest: /etc/elasticsearch/elasticsearch.yml
19 changes: 19 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Add Elastic GPG key for downloads
ansible.builtin.rpm_key:
state: present
key: https://artifacts.elastic.co/GPG-KEY-elasticsearch

- name: Add Elastic repo to instance
ansible.builtin.yum_repository:
name: elasticsearch
description: "Elasticsearch repository for {{ es_major_version }} packages"
baseurl: "https://artifacts.elastic.co/packages/{{ es_major_version }}.x/yum"
gpgcheck: yes
gpgkey: https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled: yes

- name: Install Elastic
ansible.builtin.package:
name: "elasticsearch-{{ es_major_version }}.{{ es_minor_version }}.x86_64"
state: present
6 changes: 6 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Include install tasks
ansible.builtin.include_tasks: install.yml

- name: Include configuration tasks
ansible.builtin.include_tasks: configure.yml
110 changes: 110 additions & 0 deletions templates/elasticsearch.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: {{ es_cluster_name }}
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: {{ inventory_hostname }}
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: {{ es_data_path }}
#
# Path to log files:
#
path.logs: {{ es_log_path }}
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: {{ inventory_hostname }}
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
{% if groups['master'] | length == 1 %}
discovery.type: single-node
#discovery.seed_hosts:
{% elif groups['master'] | length > 1 -%}
discovery.type: multi-node
discovery.seed_hosts:
{% for host in groups['master'] %}
- {{ hostvars[host]['ansible_default_ipv4']['address'] }} # {{ host }}
{% endfor %}
{% endif %}
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
{% if groups['master'] | length == 1 %}
#cluster.initial_master_nodes: ["node-1", "node-2"]
{% elif groups['master'] | length > 1 -%}
cluster.initial_master_nodes:
{% for host in groups['master'] %}
- {{ hostvars[host]['ansible_default_ipv4']['address'] }} # {{ host }}
{% endfor %}
{% endif %}
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
# ---------------------------------- Security -----------------------------------
{#
xpack.security.enabled: {{ es_xpack_enabled }}
xpack.security.http.ssl.enabled: {{ es_tls_enabled }}
xpack.security.transport.ssl.enabled: {{ es_tls_enabled }}
{% if es_tls_enabled == true %}
xpack.security.http.ssl.key: {{ es_tls_key }}
xpack.security.http.ssl.certificate: {{ es_tls_cert }}
xpack.security.http.ssl.certificate_authorities: {{ es_tls_ca }}
xpack.security.transport.ssl.key: {{ es_tls_key }}
xpack.security.transport.ssl.certificate: {{ es_tls_cert }}
xpack.security.transport.ssl.certificate_authorities: {{ es_tls_ca }}
{% endif %}
#}
2 changes: 2 additions & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- elasticsearch
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for elasticsearch

0 comments on commit 0cb2943

Please sign in to comment.