Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ jobs:

strategy:
matrix:
distro: [rockylinux8, rockylinux9, ubuntu2204]
scenario: [default, renew, ca-renew]
distro:
- rockylinux8
- rockylinux9
- ubuntu2204
scenario:
- default
- renew
- ca-renew
steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -37,3 +43,44 @@ jobs:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}

logstash:
runs-on: ubuntu-latest

strategy:
matrix:
distro:
- rockylinux8
- rockylinux9
- ubuntu2204
scenario:
- logstash
release:
- 7
- 8
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-test.txt
# workaround for broken galaxy information in the collection
ansible-galaxy collection install git+https://github.com/NETWAYS/ansible-collection-elasticstack.git
#mkdir -p ~/.ansible/collections/ansible-collections/netways
#git clone https://github.com/NETWAYS/ansible-collection-elasticstack.git ~/.ansible/collections/ansible-collections/netways/elasticstack

- name: ${{ matrix.scenario }} molecule test
run: |
molecule test -s ${{ matrix.scenario }}
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}
ELASTIC_RELEASE: ${{ matrix.release }}
32 changes: 32 additions & 0 deletions molecule/logstash/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# The workaround for arbitrarily named role directory is important because the
# git repo has one name and the role within it another
# Found at:
# https://github.com/ansible-community/molecule/issues/1567#issuecomment-436876722
- name: Converge
hosts: all
collections:
- netways.elasticstack
vars:
ca_ca_host: ca_default
ca_logstash: true
ca_openssl_cipher: auto
ca_ca_dir: /opt/logstash-ca
ca_keypassphrase: "moleculetest"
logstash_certs_dir: /opt/logstash-ca
logstash_beats_tls: true
elasticstack_release: "{{ lookup('env', 'ELASTIC_RELEASE') | int}}"
elasticstack_no_log: false
elasticstack_full_stack: false
tasks:
- name: "Include CA role"
include_role:
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"

- name: "Include Elastic repos role"
include_role:
name: repos

- name: "Include Logstash role"
include_role:
name: logstash
32 changes: 32 additions & 0 deletions molecule/logstash/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ca_default
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
pre_build_image: true
cgroupns_mode: host
- name: ca_default_client
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
privileged: true
pre_build_image: true
groups:
- molecule
cgroupns_mode: host
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .
30 changes: 30 additions & 0 deletions molecule/logstash/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Prepare
hosts: all
tasks:

- name: Install Python libraries
pip:
name: cryptography>= 1.2.3

- name: Install packages for RHEL
package:
name:
- iproute
- NetworkManager
when: ansible_os_family == "RedHat"

- name: Start NetworkManager
service:
name: NetworkManager
state: started
enabled: yes
when: ansible_os_family == "RedHat"

- name: Install common packages
package:
name:
- gpg
- gpg-agent
update_cache: yes
when: ansible_os_family == "Debian"
8 changes: 8 additions & 0 deletions molecule/logstash/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
roles:
collections:
- community.crypto
#- name: netways.elasticstack
# source: https://github.com/NETWAYS/ansible-collection-elasticstack.git
# scm: git
# version: main
48 changes: 48 additions & 0 deletions molecule/logstash/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

- name: Verify
hosts: all
vars:
ca_ca_dir: /opt/ca
ca_client_ca_dir: /opt/ca
tasks:

- name: Verify signature on certificate
command: >
openssl verify
-verbose
-CAfile {{ ca_ca_dir }}/ca.crt
{{ ca_client_ca_dir }}/{{ inventory_hostname }}.crt

- name: Verify signature on server certificate
command: >
openssl verify
-verbose
-CAfile {{ ca_ca_dir }}/ca.crt
{{ ca_client_ca_dir }}/{{ inventory_hostname }}-server.crt

- name: Check if instance key is present
stat:
path: "{{ ca_client_ca_dir }}/{{ inventory_hostname }}.key"
register: instance_key_stat

- name: Fail if instance key is missing
fail:
msg: "Instance key is missing"
when:
- not instance_key_stat.stat.exists | bool

- name: Check if Logstash key is present
stat:
path: "{{ ca_client_ca_dir }}/{{ inventory_hostname }}-pkcs8.key"
register: logstash_key_stat

- name: Fail if Logstash key is missing
fail:
msg: "Logstash key is missing"
when:
- not logstash_key_stat.stat.exists | bool

- name: Check for running Logstash
wait_for:
port: 5044
2 changes: 2 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
community.crypto.openssl_csr:
path: "{{ ca_client_ca_dir }}/{{ inventory_hostname }}-etcd.csr"
privatekey_path: "{{ ca_client_ca_dir }}/{{ inventory_hostname }}.key"
privatekey_passphrase: "{{ ca_keypassphrase | default(omit, true) }}"
country_name: "{{ ca_country }}"
organization_name: "{{ ca_organization }}"
common_name: "{{ inventory_hostname }}"
Expand Down Expand Up @@ -329,6 +330,7 @@
community.crypto.openssl_csr:
path: "{{ ca_client_ca_dir }}/{{ inventory_hostname }}-etcd-server.csr"
privatekey_path: "{{ ca_client_ca_dir }}/{{ inventory_hostname }}.key"
privatekey_passphrase: "{{ ca_keypassphrase | default(omit, true) }}"
country_name: "{{ ca_country }}"
organization_name: "{{ ca_organization }}"
common_name: "{{ inventory_hostname }}"
Expand Down