feat: initial commit

This commit is contained in:
Simon Cornet 2025-06-06 17:12:03 +02:00
commit 1e593545e6
14 changed files with 260 additions and 0 deletions

23
.ansible-lint Normal file
View file

@ -0,0 +1,23 @@
---
exclude_paths:
- ".gitlab/*"
- ".gitlab-ci.yml"
- "defaults/main.yaml"
- "meta/main.yaml"
- "vars/*"
kinds:
- playbook: "**/*.{yml,yaml}"
skip_list:
- "command-shell"
- "experimental"
- "git-latest"
- "no-changed-when"
- "no-handler"
- "name[casing]"
- "name[template]"
- "risky-file-permissions"
- "schema[playbook]"
- "var-naming[no-role-prefix]"

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.ansible

16
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,16 @@
---
# gitLab ci stages
stages:
# deployment
- "linting"
- "deployment"
# include jobs
include:
# deployment
- local: ".gitlab/linting.yaml"
- local: ".gitlab/deployment.yaml"

32
.gitlab/deployment.yaml Normal file
View file

@ -0,0 +1,32 @@
---
# deploy ansible/roles/common code
deployment:
stage: "deployment"
image:
name: "cr.simoncor.net/siempie/ssh-client:v25.06.03"
entrypoint: ["/bin/sh", "-c"]
rules:
# run only on push to default branch
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: "never"
# prepare ssh
before_script:
# prepare ssh
- |
# prepare ssh
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "$SSH_CONFIG" > ~/.ssh/config
echo "$SSH_DEPLOYMENT_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
# deployment commands
script:
- |
# install ansible roles dependancies
ssh $SSH_DEPLOYMENT_USER@$ANSIBLE_SERVER \
"sudo /usr/local/bin/ansible-galaxy install -r /etc/ansible/roles/requirements.yaml --force"

30
.gitlab/linting.yaml Normal file
View file

@ -0,0 +1,30 @@
---
# linting
ansible-lint:
stage: "linting"
image: "docker.io/pipelinecomponents/ansible-lint:0.79.0"
rules:
# run only on push to default branch
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: "never"
# start linting
script:
- "ansible-lint -c .ansible-lint ."
# yamllint
yamllint:
stage: "linting"
image: "registry.gitlab.com/pipeline-components/yamllint:0.35.0"
rules:
# run only on push to default branch
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: "never"
script:
# run yamllint
- "yamllint ."

30
.yamllint Normal file
View file

@ -0,0 +1,30 @@
---
extends: 'default'
rules:
braces:
max-spaces-inside: 1
forbid: true
comments:
min-spaces-from-content: 1
comments-indentation: false
empty-lines:
max: 2
indentation:
spaces: 2
check-multi-line-strings: true
line-length:
max: 120
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
new-line-at-end-of-file: 'enable'
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
truthy:
allowed-values:
- 'true'
- 'false'
quoted-strings:
quote-type: 'any'
required: true

12
README.md Normal file
View file

@ -0,0 +1,12 @@
# Overview
This role installs the prerequisites for installing Zabbix software.
## Supported Operating Systems
| Operating System | Version |
| --- | ----- |
| Debian | 12 |
| SLES | 15 |
| Ubuntu | 22.04 LTS |
| Ubuntu | 24.04 LTS |

4
defaults/main.yaml Normal file
View file

@ -0,0 +1,4 @@
---
# zabbix_version
zabbix_major_version: "7.2"

8
meta/main.yaml Normal file
View file

@ -0,0 +1,8 @@
---
galaxy_info:
author: "siempie"
description: "install and configure the prerequisites for Zabbix software"
license: "MIT"
role_name: "zabbix_prereq"
dependencies: []

7
renovate.json Normal file
View file

@ -0,0 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [ "local>cicd/renovate" ],
"ansible": {
"fileMatch": [ "(.*).ya?ml$" ]
}
}

23
tasks/main.yaml Normal file
View file

@ -0,0 +1,23 @@
---
# load variables and collect version information
- name: "include vars and collect versions"
block:
# load os specific variables
- name: "include os specific vars"
ansible.builtin.include_vars: "{{ ansible_os_family }}.yaml"
# collect zabbix-agent2 version information
- name: "collect version information"
ansible.builtin.shell:
cmd: "apt policy | grep 'zabbix/' | head -n 1"
changed_when: false
failed_when: false
ignore_errors: true
register: "zabbix_current_version"
# zabbix-agent prerequisites
- name: "zabbix-agent prerequisites"
ansible.builtin.import_tasks: "prerequisites.yaml"

52
tasks/prerequisites.yaml Normal file
View file

@ -0,0 +1,52 @@
---
# install repository
- name: "install repository"
when: "zabbix_major_version not in zabbix_current_version.stdout"
block:
# install repository - debian
- name: "install repository"
when: 'ansible_os_family == "Debian"'
block:
- name: "remove old zabbix-release"
ansible.builtin.apt:
name: "zabbix-release"
state: "absent"
purge: true
- name: "install zabbix-release"
ansible.builtin.apt:
deb: "{{ zabbix_repo_url[ansible_distribution][ansible_distribution_major_version | int] }}"
state: "present"
force: true
- name: "refresh apt cache"
ansible.builtin.apt:
update_cache: true
# install repository - suse
- name: "install repository"
when: 'ansible_os_family == "Suse"'
block:
- name: "remove old zabbix-release"
ansible.builtin.zypper:
name: "zabbix-release"
state: "absent"
- name: "install zabbix-release"
ansible.builtin.zypper:
name: "{{ zabbix_repo_url[ansible_distribution_major_version | int] }}"
state: "present"
disable_recommends: false
nosignature: true
validate_certs: true
- name: "import gpg key"
community.general.zypper_repository:
name: "Zabbix Official Repository"
auto_import_keys: true
runrefresh: true

15
vars/Debian.yaml Normal file
View file

@ -0,0 +1,15 @@
---
# zabbix repository url
zabbix_repo_url:
Debian:
12:
"https://repo.zabbix.com/zabbix/{{ zabbix_major_version }}/release/debian/pool/main/z/zabbix-release/\
zabbix-release_latest_{{ zabbix_major_version }}+debian12_all.deb"
Ubuntu:
24:
"https://repo.zabbix.com/zabbix/{{ zabbix_major_version }}/release/ubuntu/pool/main/z/zabbix-release/\
zabbix-release_latest_{{ zabbix_major_version }}+ubuntu24.04_all.deb"
22:
"https://repo.zabbix.com/zabbix/{{ zabbix_major_version }}/release/ubuntu/pool/main/z/zabbix-release/\
zabbix-release_latest_{{ zabbix_major_version }}+ubuntu22.04_all.deb"

7
vars/Suse.yaml Normal file
View file

@ -0,0 +1,7 @@
---
# zabbix repository url
zabbix_repo_url:
15:
"https://repo.zabbix.com/zabbix/{{ zabbix_major_version }}/release/sles/\
15/noarch/zabbix-release-latest-{{ zabbix_major_version }}.sles15.noarch.rpm"