Skip to content

Commit

Permalink
Added Molecule testing
Browse files Browse the repository at this point in the history
Added OS support: CentOS 8, Ubuntu Xenial and Oracle Linux 8
Added testing of the creation of the ClickHouse + Vector + LightHouse stand
  • Loading branch information
Shishkov Vladislav committed Nov 18, 2024
1 parent d4aaad4 commit 62940b9
Show file tree
Hide file tree
Showing 31 changed files with 644 additions and 53 deletions.
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
2 changes: 2 additions & 0 deletions meta/.galaxy_install_info
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
install_date: 'Sat 09 Nov 2024 05:32:49 PM '
version: 1.0.0
59 changes: 16 additions & 43 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
role_name: lighthouse
namespace: cachmc
author: Vladislav Shishkov

# 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
description: Installation and configuration LightHouse by VKCOM

# 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: license (GPL-2.0-or-later, MIT, etc)
license: MIT

min_ansible_version: 2.1
min_ansible_version: 2.13

# 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: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
platforms:
- name: CentOS
versions:
- 8
- name: Oracle Linux
versions:
- 8
- name: Ubuntu
version:
- Xenial

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.
13 changes: 13 additions & 0 deletions molecule/centos_8/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

RUN yum update -y

RUN yum install -y nano
7 changes: 7 additions & 0 deletions molecule/centos_8/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: LightHouse
hosts: all
tasks:
- name: "Include lighthouse"
include_role:
name: "lighthouse"
21 changes: 21 additions & 0 deletions molecule/centos_8/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: centos_8
image: docker.io/library/centos:8
pre_build_image: false
dockerfile: Dockerfile.j2
command: /usr/sbin/init
privileged: true
capabilities:
- SYS_ADMIN
provisioner:
name: ansible
verifier:
name: ansible
lint: |
yamllint .
ansible-lint .
10 changes: 10 additions & 0 deletions molecule/centos_8/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
13 changes: 13 additions & 0 deletions molecule/full_stand/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

RUN yum update -y

RUN yum install -y sudo nano
119 changes: 119 additions & 0 deletions molecule/full_stand/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
### ClickHouse
- name: Install ClickHouse
hosts: clickhouse

vars:
ansible_pkg_mgr: "yum"

pre_tasks:
- name: Create group 'clickhouse'
become: true
ansible.builtin.group:
name: clickhouse
state: present

- name: Create user 'clickhouse'
become: true
ansible.builtin.user:
name: clickhouse
group: clickhouse
create_home: true
expires: -1

- name: Create directory '/run/clickhouse-server'
become: true
ansible.builtin.file:
name: /run/clickhouse-server
owner: clickhouse
group: clickhouse
state: directory

roles:
- role: clickhouse

post_tasks:
- name: Gather list of existing tables
ansible.builtin.command: "clickhouse-client -q 'SHOW TABLES FROM {{ item.name }};'"
changed_when: false
with_items: "{{ clickhouse_dbs_custom }}"
register: existing_tables

- name: Show existing tables
debug:
msg: |
{% for table in existing_tables.results %}
{% if item.name == table.item.name %}
{{ table.stdout_lines }}
{% endif %}
{% endfor %}
with_items: "{{ clickhouse_dbs_custom }}"

- name: Create table
ansible.builtin.command: "clickhouse-client -q 'CREATE TABLE IF NOT EXISTS \
{{ item.item.name }}.{{ clickhouse_table_name }} (message String) \
ENGINE = MergeTree() ORDER BY tuple();'"
when: clickhouse_table_name not in item.stdout_lines
with_items: "{{ existing_tables.results }}"


### Vector
- name: Install Vector
hosts: vector

roles:
- role: vector


### LightHouse
- name: Install LightHouse
hosts: lighthouse

handlers:
- name: Reload nginx service
become: true
ansible.builtin.command: "/usr/sbin/nginx -s reload"
register: reload_nginx
failed_when: reload_nginx.rc != 0
changed_when: reload_nginx.rc == 0
listen: nginx_reload

- name: Start nginx service
become: true
ansible.builtin.systemd:
name: nginx
state: restarted
listen: nginx_start

tasks:
- name: "Include lighthouse"
include_role:
name: "lighthouse"

post_tasks:
- name: Install nginx package
become: true
ansible.builtin.yum:
name: nginx
notify: nginx_start

- name: Flush handlers
ansible.builtin.meta: flush_handlers

- name: Copy config file nginx.conf
become: true
ansible.builtin.template:
src: "{{ item.src }}"
dest: "/etc/nginx/{{ item.dest }}"
mode: "{{ item.mode }}"
backup: true
with_items:
- { src: './templates/nginx.conf.j2', dest: 'nginx.conf', mode: '0644' }
- { src: './templates/nginx_lighthouse.conf.j2', dest: 'conf.d/lighthouse.conf', mode: '0644' }
notify: nginx_reload

- name: Enable nginx service
become: true
ansible.builtin.systemd:
name: nginx
enabled: true
32 changes: 32 additions & 0 deletions molecule/full_stand/host_vars/clickhouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
ansible_pkg_mgr: "yum"
clickhouse_version: "22.3.3.44"
clickhouse_listen_host:
- "127.0.0.1"
- "10.10.50.11"
clickhouse_profiles_custom:
vector:
max_memory_usage: 10000000000
use_uncompressed_cache: 0
load_balancing: random
readonly: 0
clickhouse_users_custom:
- { name: "lighthouse",
password: "lighthouse",
networks: { "::/0" },
profile: "default",
quota: "default",
dbs: [ logs ],
comment: "User for LightHouse"}
- { name: "vector",
password: "vector",
networks: { "::/0" },
profile: "vector",
quota: "default",
dbs: [ logs ],
comment: "User for Vector"}
clickhouse_dbs_custom:
- { name: logs }
clickhouse_table_name: "random_log"
clickhouse_repo: "https://packages.clickhouse.com/rpm/stable/"
clickhouse_repo_key: "https://packages.clickhouse.com/rpm/stable/repodata/repomd.xml.key"
7 changes: 7 additions & 0 deletions molecule/full_stand/host_vars/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
lighthouse_install_path: "/opt/lighthouse"
lighthouse_ch_address: "10.10.50.11"
lighthouse_ch_user: "lighthouse"
lighthouse_ch_password: "lighthouse"
lighthouse_ch_db: "logs"
lighthouse_ch_table: "random_log"
10 changes: 10 additions & 0 deletions molecule/full_stand/host_vars/vector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
vector_version: "0.42.0"
vector_ch_address: "10.10.50.11"
vector_ch_user: "vector"
vector_ch_password: "vector"
vector_ch_port: "8123"
vector_ch_db_name: "logs"
vector_ch_table_name: "random_log"
vector_configs_add:
clickhouse: "{{ lookup('template', './templates/clickhouse.yaml.j2') }}"
Loading

0 comments on commit 62940b9

Please sign in to comment.