Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev tools configuration #54

Merged
merged 6 commits into from
Feb 22, 2024
Merged
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
2 changes: 2 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
skip_list:
- 'var-naming[no-role-prefix]'
41 changes: 12 additions & 29 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
name: 'Lint'
on:
pull_request: {}
push: {}
pull_request: { }
push: { }

jobs:
lint:
name: 'Lint'
runs-on: ubuntu-latest
container:
image: python:3.9-alpine
steps:
- name: 'Checkout'
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup ansible
run: |
apk add --update --no-cache --virtual build_dependencies gcc musl-dev libffi-dev openssl-dev rust cargo
pip install --no-cache-dir ansible-core

ansible-galaxy collection install community.general

- name: 'Yamllint'
uses: karancode/yamllint-github-action@master
- name: Cache .venv directory
uses: actions/cache@v3
with:
yamllint_file_or_dir: 'roles'
yamllint_strict: false
yamllint_comment: false
path: .venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements.txt') }}

- name: Checkout
uses: actions/checkout@v3

- name: "Ansible lint playbooks"
uses: ansible/[email protected]
with:
path: "playbooks/*"

- name: "Ansible lint roles"
uses: ansible/[email protected]
with:
path: "roles/*"
- name: Lint
run: |
make init-venv

make lint
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ permissions:
on:
create:
tags:
- v*
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
release:
runs-on: ubuntu-latest
container:
image: python:3.9-alpine
image: python:3.11-alpine
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Publish collection to ansible galaxy
env:
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'Molecule Test'
on:
pull_request: { }
push:
branches:
- master

jobs:
lint:
name: 'Test'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: Cache .venv directory
uses: actions/cache@v3
with:
path: .venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements.txt') }}

- name: Converge
run: |
make init-venv

make molecule-converge
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vagrant
.vscode
.venv
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
init-venv:
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
ansible-galaxy collection install community.general==8.3.0

venv:
. .venv/bin/activate

lint: venv
yamllint roles playbooks
ansible-lint roles/ playbooks/

molecule-converge: venv
cd roles/single && molecule converge -s docker
cd roles/vmagent && molecule converge -s docker
cd roles/vmalert && molecule converge -s docker

molecule-destroy: venv
cd roles/single && molecule destroy -s docker
cd roles/vmagent && molecule destroy -s docker
cd roles/vmalert && molecule destroy -s docker
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ Collection includes the following roles:
- add non-docker environment
- fix hardcoded ports

# Testing
# Development

I'm using vagrant and libvirt for testing purpose. visit vendors' web-site for instructions of installing program.
vagrant: https://www.vagrantup.com/downloads
In order to set up development environment, you need to have `docker`, `python` and `make` installed.
Run `make init-venv` to create virtual environment and install required packages for linting and testing with [molecule](https://ansible.readthedocs.io/projects/molecule).

Also, most roles are tested with `molecule`. Please, check out installation docs: https://ansible.readthedocs.io/projects/molecule/installation/
Please, note that [cluster](./roles/cluster) role is tested with `vagrant` and `libvirt` provider and requires `vagrant` [to be installed](https://www.vagrantup.com/downloads).

Refer to [Makefile](./Makefile) for available commands for linting and molecule testing.
2 changes: 2 additions & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ build_ignore:
- inventory_example
- Vagrantfile
- '*.tar.gz'
- Makefile
- requirements.txt
homepage: "https://github.com/VictoriaMetrics/ansible-playbooks"
documentation: "https://github.com/VictoriaMetrics/ansible-playbooks"
issues: "https://github.com/VictoriaMetrics/ansible-playbooks/issues"
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ansible-compat==4.1.11
ansible-core==2.16.3
ansible-lint==24.2.0
docker==7.0.0
molecule==24.2.0
molecule-plugins==23.5.3
yamllint==1.35.1
2 changes: 1 addition & 1 deletion roles/cluster/molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ansible.builtin.get_url:
url: "{{ goss_url }}"
dest: "{{ goss_bin }}"
sha256sum: "{{ goss_sha256sum }}"
sha256sum: "{{ goss_sha256sum }}" # noqa: args[module]
mode: "u=rwx,go=rx"
register: download_goss
until: download_goss is succeeded
Expand Down
16 changes: 16 additions & 0 deletions roles/single/molecule/docker/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Converge
hosts: all
become: yes
vars:
victoriametrics_data_dir: "/tmp/victoria-metrics/"
victoriametrics_backup_enabled: false
victoriametrics_service_envflag_enabled: true
victoriametrics_service_envflag_data:
- "graphiteListenAddr=127.0.0.1:12345"
victoriametrics_service_args:
storageDataPath: "{{ victoriametrics_data_dir }}"
tasks:
- name: "Include single"
ansible.builtin.include_role:
name: "single"
27 changes: 27 additions & 0 deletions roles/single/molecule/docker/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
lint: |
yamllint .
ansible-lint .


dependency:
name: galaxy

driver:
name: docker

platforms:
- name: vmsingle-debian11
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true

provisioner:
name: ansible

verifier:
name: ansible
31 changes: 31 additions & 0 deletions roles/single/molecule/docker/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
tasks:
- name: Check if port 12345 is listening
ansible.builtin.wait_for:
port: 12345
delay: 5
timeout: 10
msg: "Timeout waiting for port to respond"
register: port_check
ignore_errors: yes

- name: Validate victoria is listening
ansible.builtin.assert:
that: port_check is succeeded

- name: Check if port 8428 is listening
ansible.builtin.wait_for:
port: 8428
delay: 5
timeout: 10
msg: "Timeout waiting for port to respond"
register: port_check
ignore_errors: yes

- name: Validate victoria is listening
ansible.builtin.assert:
that: port_check is succeeded
6 changes: 3 additions & 3 deletions roles/single/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
- not victoriametrics_is_installed.stat.exists or
victoriametrics_version not in victoriametrics_current_version.stdout

- name: Upload VictoriaMetrics release binary
- name: Upload VictoriaMetrics release binary # noqa: no-handler
ansible.builtin.copy:
src: /tmp/vic-single/victoria-metrics-prod
dest: /usr/local/bin
Expand All @@ -82,7 +82,7 @@
when:
- archive_downloaded is changed

- name: Download VictoriaMetrics utils
- name: Download VictoriaMetrics utils # noqa: no-handler
become: no
environment:
http_proxy: ''
Expand All @@ -95,7 +95,7 @@
when:
- archive_downloaded is changed

- name: Upload VictoriaMetrics release binaries
- name: Upload VictoriaMetrics release binaries # noqa: no-handler
ansible.builtin.copy:
src: "/tmp/vic-utils/{{ item }}"
dest: /usr/local/bin
Expand Down
4 changes: 2 additions & 2 deletions roles/single/tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- hosts: all
name: Test role
- name: Test role
hosts: all
become: true
roles:
- "single"
2 changes: 1 addition & 1 deletion roles/vmagent/molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ansible.builtin.get_url:
url: "{{ goss_url }}"
dest: "{{ goss_bin }}"
sha256sum: "{{ goss_sha256sum }}"
sha256sum: "{{ goss_sha256sum }}" # noqa: args[module]
mode: "u=rwx,go=rx"
register: download_goss
until: download_goss is succeeded
Expand Down
8 changes: 8 additions & 0 deletions roles/vmagent/molecule/docker/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
become: yes
tasks:
- name: "Include vmagent"
ansible.builtin.include_role:
name: "vmagent"
25 changes: 25 additions & 0 deletions roles/vmagent/molecule/docker/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
lint: |
yamllint .
ansible-lint .


dependency:
name: galaxy
driver:
name: docker

platforms:
- name: vmagent-debian11
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true

provisioner:
name: ansible
verifier:
name: ansible
4 changes: 4 additions & 0 deletions roles/vmagent/molecule/docker/tests/test_default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
service:
"vic-vmagent":
enabled: true
running: true
Loading
Loading