From 0cb2943b4693645d82078847da002cdbef8bb00d Mon Sep 17 00:00:00 2001 From: pictowolf Date: Sat, 13 Aug 2022 15:16:23 +0000 Subject: [PATCH] Install ES --- .travis.yml | 29 +++++++++ .yamllint | 33 ++++++++++ README.md | 29 +++++++++ defaults/main.yml | 8 +++ handlers/main.yml | 2 + meta/main.yml | 52 ++++++++++++++++ molecule/default/converge.yml | 7 +++ molecule/default/molecule.yml | 22 +++++++ molecule/default/verify.yml | 10 +++ tasks/configure.yml | 5 ++ tasks/install.yml | 19 ++++++ tasks/main.yml | 6 ++ templates/elasticsearch.yml.j2 | 110 +++++++++++++++++++++++++++++++++ tests/inventory | 2 + tests/test.yml | 5 ++ vars/main.yml | 2 + 16 files changed, 341 insertions(+) create mode 100644 .travis.yml create mode 100644 .yamllint create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/verify.yml create mode 100644 tasks/configure.yml create mode 100644 tasks/install.yml create mode 100644 tasks/main.yml create mode 100644 templates/elasticsearch.yml.j2 create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/.travis.yml @@ -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/ \ No newline at end of file diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..8827676 --- /dev/null +++ b/.yamllint @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..5542a8a --- /dev/null +++ b/README.md @@ -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 + diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..b7da1e0 --- /dev/null +++ b/defaults/main.yml @@ -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 \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..9d59325 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for elasticsearch diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..07a6748 --- /dev/null +++ b/meta/main.yml @@ -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. diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..c4f40c2 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include pictowolf.elasticsearch" + include_role: + name: "pictowolf.elasticsearch" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..c753c5a --- /dev/null +++ b/molecule/default/molecule.yml @@ -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 diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..e707420 --- /dev/null +++ b/molecule/default/verify.yml @@ -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 diff --git a/tasks/configure.yml b/tasks/configure.yml new file mode 100644 index 0000000..fa3e75b --- /dev/null +++ b/tasks/configure.yml @@ -0,0 +1,5 @@ +--- +- name: Set elasticsearch.yml + ansible.builtin.template: + src: elasticsearch.yml.j2 + dest: /etc/elasticsearch/elasticsearch.yml \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..8bed754 --- /dev/null +++ b/tasks/install.yml @@ -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 \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..7491d11 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: Include install tasks + ansible.builtin.include_tasks: install.yml + +- name: Include configuration tasks + ansible.builtin.include_tasks: configure.yml \ No newline at end of file diff --git a/templates/elasticsearch.yml.j2 b/templates/elasticsearch.yml.j2 new file mode 100644 index 0000000..8a0755e --- /dev/null +++ b/templates/elasticsearch.yml.j2 @@ -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 %} +#} \ No newline at end of file diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..3af8875 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - elasticsearch diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..140916a --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for elasticsearch