From 4fd9459edccbbf48568b8f7af5d4a5633af37437 Mon Sep 17 00:00:00 2001 From: Giovanni Toraldo Date: Thu, 22 Sep 2022 10:55:36 +0200 Subject: [PATCH] OPSEXP-1635 add elasticsearch role (#432) --- .github/workflows/community.yml | 1 + requirements.yml | 5 +++ roles/elasticsearch/defaults/main.yml | 4 +++ roles/elasticsearch/handlers/main.yml | 2 ++ roles/elasticsearch/meta/main.yml | 26 ++++++++++++++ .../molecule/default/converge.yml | 7 ++++ .../host_vars/elasticsearch-instance.yml | 1 + .../molecule/default/molecule.yml | 27 +++++++++++++++ .../elasticsearch/molecule/default/verify.yml | 34 +++++++++++++++++++ roles/elasticsearch/tasks/main.yml | 25 ++++++++++++++ roles/elasticsearch/vars/main.yml | 2 ++ 11 files changed, 134 insertions(+) create mode 100644 roles/elasticsearch/defaults/main.yml create mode 100644 roles/elasticsearch/handlers/main.yml create mode 100644 roles/elasticsearch/meta/main.yml create mode 100644 roles/elasticsearch/molecule/default/converge.yml create mode 100644 roles/elasticsearch/molecule/default/host_vars/elasticsearch-instance.yml create mode 100644 roles/elasticsearch/molecule/default/molecule.yml create mode 100644 roles/elasticsearch/molecule/default/verify.yml create mode 100644 roles/elasticsearch/tasks/main.yml create mode 100644 roles/elasticsearch/vars/main.yml diff --git a/.github/workflows/community.yml b/.github/workflows/community.yml index 052dd4e9a..995ef3aed 100644 --- a/.github/workflows/community.yml +++ b/.github/workflows/community.yml @@ -22,6 +22,7 @@ jobs: role: - name: activemq - name: common + - name: elasticsearch - name: java - name: nginx - name: postgres diff --git a/requirements.yml b/requirements.yml index e783f088e..06645b23d 100644 --- a/requirements.yml +++ b/requirements.yml @@ -18,3 +18,8 @@ collections: # molecule roles tests - name: community.docker version: 2.1.1 +roles: + - name: buluma.elastic_repo + version: v0.1.2 + - name: buluma.elasticsearch + version: 1.0.2 \ No newline at end of file diff --git a/roles/elasticsearch/defaults/main.yml b/roles/elasticsearch/defaults/main.yml new file mode 100644 index 000000000..7454b952c --- /dev/null +++ b/roles/elasticsearch/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for elasticsearch +elasticsearch_tmp_path: /usr/share/elasticsearch/tmp +elasticsearch_systemd_service_path: /etc/systemd/system/elasticsearch.service.d/ diff --git a/roles/elasticsearch/handlers/main.yml b/roles/elasticsearch/handlers/main.yml new file mode 100644 index 000000000..9d59325ee --- /dev/null +++ b/roles/elasticsearch/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for elasticsearch diff --git a/roles/elasticsearch/meta/main.yml b/roles/elasticsearch/meta/main.yml new file mode 100644 index 000000000..859f036ef --- /dev/null +++ b/roles/elasticsearch/meta/main.yml @@ -0,0 +1,26 @@ +galaxy_info: + author: alfresco + namespace: alfresco + description: Install elasticsearch required by Search Enteprise + company: Hyland Software + + license: Apache-2.0 + + min_ansible_version: "2.12" + + platforms: + - name: Ubuntu + versions: + - focal + - bionic + - name: EL + versions: + - "7" + - "8" + + galaxy_tags: [] + +dependencies: + - role: common + - role: buluma.elastic_repo + become: true diff --git a/roles/elasticsearch/molecule/default/converge.yml b/roles/elasticsearch/molecule/default/converge.yml new file mode 100644 index 000000000..d6c165b36 --- /dev/null +++ b/roles/elasticsearch/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include elasticsearch" + include_role: + name: "elasticsearch" diff --git a/roles/elasticsearch/molecule/default/host_vars/elasticsearch-instance.yml b/roles/elasticsearch/molecule/default/host_vars/elasticsearch-instance.yml new file mode 100644 index 000000000..146ddd8e0 --- /dev/null +++ b/roles/elasticsearch/molecule/default/host_vars/elasticsearch-instance.yml @@ -0,0 +1 @@ +ansible_user: ansible diff --git a/roles/elasticsearch/molecule/default/molecule.yml b/roles/elasticsearch/molecule/default/molecule.yml new file mode 100644 index 000000000..9b592aa0e --- /dev/null +++ b/roles/elasticsearch/molecule/default/molecule.yml @@ -0,0 +1,27 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: elasticsearch-instance + image: ${MOLECULE_ROLE_IMAGE:-ubuntu:18.04} + dockerfile: ../../../../tests/molecule/Dockerfile-noprivs.j2 + command: "/lib/systemd/systemd" + privileged: true + tmpfs: + - /run + - /run/lock + - /tmp + volume_mounts: + - "/sys/fs/cgroup:/sys/fs/cgroup:ro" + groups: + - elasticsearch +provisioner: + name: ansible + inventory: + links: + host_vars: host_vars + group_vars: ../../../../group_vars +verifier: + name: ansible diff --git a/roles/elasticsearch/molecule/default/verify.yml b/roles/elasticsearch/molecule/default/verify.yml new file mode 100644 index 000000000..ef2102737 --- /dev/null +++ b/roles/elasticsearch/molecule/default/verify.yml @@ -0,0 +1,34 @@ +- name: Verify + hosts: all + gather_facts: false + tasks: + + - name: Stat the tmp folder for elasticsearch + stat: + path: "/usr/share/elasticsearch/tmp" + register: tmp_path_stat + + - name: Assert that tmp folder is setup correctly + ansible.builtin.assert: + that: + - tmp_path_stat.stat.exists + - tmp_path_stat.stat.isdir + - tmp_path_stat.stat.mode == '0777' + - tmp_path_stat.stat.uid == 0 + - tmp_path_stat.stat.gid == 0 + + - name: Check if port 9200/tcp is listening + wait_for: + port: 9200 + timeout: 30 + connect_timeout: 1 + msg: "Timeout waiting for 9200/tcp to respond" + + - name: Populate service facts + ansible.builtin.service_facts: + + - name: Elasticsearch service is up and running + ansible.builtin.assert: + that: + - ansible_facts.services['elasticsearch.service'] is defined + - ansible_facts.services['elasticsearch.service'].state == 'running' diff --git a/roles/elasticsearch/tasks/main.yml b/roles/elasticsearch/tasks/main.yml new file mode 100644 index 000000000..631fd5178 --- /dev/null +++ b/roles/elasticsearch/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# tasks file for elasticsearch +- name: Install elasticsearch + become: true + block: + # https://github.com/buluma/ansible-role-elasticsearch/issues/25 + - name: Create alternative tmp directory for elasticsearch + ansible.builtin.file: + path: "{{ elasticsearch_tmp_path }}" + state: directory + mode: "0777" + - name: Create override directory for elasticsearch.service + ansible.builtin.file: + path: "{{ elasticsearch_systemd_service_path }}" + state: directory + mode: "0755" + - name: Set tmpdir override for elasticsearch.service + ansible.builtin.copy: + content: | + [Service] + Environment="ES_TMPDIR={{ elasticsearch_tmp_path }}" + dest: "{{ elasticsearch_systemd_service_path }}/tmpdir.conf" + - name: Install elasticsearch + ansible.builtin.include_role: + name: buluma.elasticsearch diff --git a/roles/elasticsearch/vars/main.yml b/roles/elasticsearch/vars/main.yml new file mode 100644 index 000000000..140916a91 --- /dev/null +++ b/roles/elasticsearch/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for elasticsearch