Compare commits
16 commits
Author | SHA1 | Date | |
---|---|---|---|
beb469878e | |||
118d86bfe0 | |||
8aa3a9cbaa | |||
a1cd7135a3 | |||
34e6590bcc | |||
58b7253198 | |||
eaf0b7e0c7 | |||
a0efb0d8db | |||
2118e694cd | |||
b3bc69a025 | |||
4915f4792d | |||
e2ed6fb9b5 | |||
32911bac43 | |||
e4c6a27409 | |||
2dd145bede | |||
e3a7c76773 |
20 changed files with 265 additions and 116 deletions
18
.forgejo/workflows/molecule.yml
Normal file
18
.forgejo/workflows/molecule.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: code.waks.be/nishiki/molecule:docker
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: ansible-lint .
|
||||||
|
- run: yamllint .
|
||||||
|
molecule:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: code.waks.be/nishiki/molecule:docker
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: molecule test
|
10
.gitlab-ci.yml
Normal file
10
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
image: nishiki/molecule:docker
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- molecule --version
|
||||||
|
|
||||||
|
molecule:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- molecule test
|
|
@ -2,11 +2,11 @@
|
||||||
extends: default
|
extends: default
|
||||||
|
|
||||||
ignore: |
|
ignore: |
|
||||||
.kitchen/*
|
.kitchen*
|
||||||
vendor/
|
vendor/
|
||||||
|
.forgejo/
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
line-length:
|
line-length:
|
||||||
max: 120
|
max: 120
|
||||||
level: warning
|
level: warning
|
||||||
truthy: false
|
|
||||||
|
|
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -5,6 +5,25 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- add dependencies
|
||||||
|
- add options in host
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- test: use personal docker registry
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- bug in check command template
|
||||||
|
- bug in user template
|
||||||
|
- add multiple value type in service vars
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- test: remove support debian11
|
||||||
|
|
||||||
## v1.0.0 - 2021-08-15
|
## v1.0.0 - 2021-08-15
|
||||||
|
|
||||||
- first version
|
- first version
|
||||||
|
|
35
README.md
35
README.md
|
@ -1,16 +1,16 @@
|
||||||
# Ansible role: Icinga2
|
# Ansible role: Icinga2
|
||||||
|
|
||||||
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-icinga2/releases)
|
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://code.waks.be/nishiki/ansible-role-icinga2/releases)
|
||||||
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-icinga2/src/branch/master/LICENSE)
|
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://code.waks.be/nishiki/ansible-role-icinga2/src/branch/main/LICENSE)
|
||||||
|
[![Build](https://code.waks.be/nishiki/ansible-role-icinga2/actions/workflows/molecule.yml/badge.svg?branch=main)](https://code.waks.be/nishiki/ansible-role-icinga2/actions?workflow=molecule.yml)
|
||||||
|
|
||||||
Install and configure Icinga2
|
Install and configure Icinga2
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Ansible >= 2.9
|
- Ansible >= 2.9
|
||||||
* Debian
|
- Debian
|
||||||
* Buster
|
- Bookworm
|
||||||
* Bullseye
|
|
||||||
|
|
||||||
## Role variables
|
## Role variables
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ Install and configure Icinga2
|
||||||
- admin
|
- admin
|
||||||
```
|
```
|
||||||
|
|
||||||
- `icinga2_api_users` - hash with the user configuration for the API access
|
- `icinga2_api_users` - hash with the user configuration for the API access
|
||||||
|
|
||||||
```
|
```
|
||||||
icingaweb2:
|
icingaweb2:
|
||||||
|
@ -148,6 +148,19 @@ Install and configure Icinga2
|
||||||
monday: 00:05-00:10
|
monday: 00:05-00:10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- `icinga2_dependencies` - hash with dependencies configuration ([view all options](https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#dependency))
|
||||||
|
|
||||||
|
```
|
||||||
|
postgresql-port:
|
||||||
|
parent_host_name: host.name
|
||||||
|
parent_service_name: postgresql-service
|
||||||
|
child_service_name: postgresql-port
|
||||||
|
disable_notifications: true
|
||||||
|
states:
|
||||||
|
- DOWN
|
||||||
|
assign: '"postgresql" in host.groups'
|
||||||
|
```
|
||||||
|
|
||||||
- `icinga2_notifications` - hash with notifications configuration
|
- `icinga2_notifications` - hash with notifications configuration
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -232,10 +245,10 @@ Install and configure Icinga2
|
||||||
|
|
||||||
### Test with molecule and docker
|
### Test with molecule and docker
|
||||||
|
|
||||||
* install [docker](https://docs.docker.com/engine/installation/)
|
- install [docker](https://docs.docker.com/engine/installation/)
|
||||||
* install `python3` and `python3-pip`
|
- install `python3` and `python3-pip`
|
||||||
* install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint testinfra yamllint`
|
- install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint testinfra yamllint`
|
||||||
* run `molecule test`
|
- run `molecule test`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -107,4 +107,5 @@ icinga2_users: {}
|
||||||
icinga2_api_users: {}
|
icinga2_api_users: {}
|
||||||
icinga2_check_commands: {}
|
icinga2_check_commands: {}
|
||||||
icinga2_event_commands: {}
|
icinga2_event_commands: {}
|
||||||
|
icinga2_dependencies: {}
|
||||||
icinga2_scripts: {}
|
icinga2_scripts: {}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
---
|
---
|
||||||
- name: reload icinga2
|
- name: Reload icinga2
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: icinga2
|
name: icinga2
|
||||||
state: reloaded
|
state: reloaded
|
||||||
|
|
||||||
- name: restart icinga2
|
- name: Restart icinga2
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: icinga2
|
name: icinga2
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
---
|
---
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
role_name: icinga2
|
role_name: icinga2
|
||||||
|
namespace: nishiki
|
||||||
author: Adrien Waksberg
|
author: Adrien Waksberg
|
||||||
company: Adrien Waksberg
|
company: Adrien Waksberg
|
||||||
description: Install and configure Icinga2
|
description: Install and configure Icinga2
|
||||||
license: Apache2
|
license: Apache2
|
||||||
min_ansible_version: 2.9
|
min_ansible_version: "2.9"
|
||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- buster
|
- bookworm
|
||||||
- bullseye
|
|
||||||
|
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- monitoring
|
- monitoring
|
||||||
|
|
|
@ -50,3 +50,8 @@
|
||||||
icinga2_event_commands:
|
icinga2_event_commands:
|
||||||
ping_event:
|
ping_event:
|
||||||
command: '"/usr/bin/ping -c 1 -t 1 127.0.0.1"'
|
command: '"/usr/bin/ping -c 1 -t 1 127.0.0.1"'
|
||||||
|
icinga2_dependencies:
|
||||||
|
test:
|
||||||
|
parent_host_name: host.name
|
||||||
|
disable_notifications: false
|
||||||
|
assign: "true"
|
||||||
|
|
|
@ -2,19 +2,12 @@
|
||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
platforms:
|
platforms:
|
||||||
- name: debian10
|
- name: debian12
|
||||||
image: nishiki/debian10:molecule
|
image: code.waks.be/nishiki/molecule:debian12
|
||||||
privileged: true
|
privileged: true
|
||||||
volumes:
|
volumes:
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
command: /bin/systemd
|
cgroupns_mode: host
|
||||||
capabilities:
|
|
||||||
- SYS_ADMIN
|
|
||||||
- name: debian11
|
|
||||||
image: nishiki/debian11:molecule
|
|
||||||
privileged: true
|
|
||||||
volumes:
|
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
|
||||||
command: /bin/systemd
|
command: /bin/systemd
|
||||||
capabilities:
|
capabilities:
|
||||||
- SYS_ADMIN
|
- SYS_ADMIN
|
||||||
|
|
|
@ -77,6 +77,15 @@ def test_config_notifications(host):
|
||||||
assert config.mode == 0o640
|
assert config.mode == 0o640
|
||||||
assert config.contains('user_groups = host.vars.notification.mail.groups')
|
assert config.contains('user_groups = host.vars.notification.mail.groups')
|
||||||
|
|
||||||
|
def test_config_dependencies(host):
|
||||||
|
config = host.file('/etc/icinga2/conf.d/dependencies.conf')
|
||||||
|
assert config.exists
|
||||||
|
assert config.is_file
|
||||||
|
assert config.user == 'root'
|
||||||
|
assert config.group == 'nagios'
|
||||||
|
assert config.mode == 0o640
|
||||||
|
assert config.contains('parent_host_name = host.name')
|
||||||
|
|
||||||
def test_script(host):
|
def test_script(host):
|
||||||
path = host.file('/etc/icinga2/scripts/test-notification.sh')
|
path = host.file('/etc/icinga2/scripts/test-notification.sh')
|
||||||
assert path.exists
|
assert path.exists
|
||||||
|
|
|
@ -1,47 +1,44 @@
|
||||||
---
|
---
|
||||||
- name: install dependencies packages
|
- name: Install dependencies packages
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
name:
|
name:
|
||||||
- apt-transport-https
|
- apt-transport-https
|
||||||
- gpg
|
- gpg
|
||||||
retries: 2
|
|
||||||
register: result
|
|
||||||
until: result is succeeded
|
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: add key repository
|
- name: Add repository key
|
||||||
ansible.builtin.apt_key:
|
ansible.builtin.get_url:
|
||||||
url: https://packages.icinga.com/icinga.key
|
url: https://packages.icinga.com/icinga.key
|
||||||
retries: 2
|
dest: /etc/apt/keyrings/icinga.asc
|
||||||
register: result
|
owner: root
|
||||||
until: result is succeeded
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
checksum: sha256:be677e07972ed57b99ffc2fd211379ac11b9c6a7c8d9460086b447b96b0a82bb
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: add repository
|
- name: Add repository
|
||||||
ansible.builtin.apt_repository:
|
ansible.builtin.apt_repository:
|
||||||
repo: 'deb https://packages.icinga.com/debian icinga-{{ ansible_distribution_release }} main'
|
repo: >-
|
||||||
retries: 2
|
deb [signed-by=/etc/apt/keyrings/icinga.asc]
|
||||||
register: result
|
https://packages.icinga.com/debian icinga-{{ ansible_distribution_release }} main
|
||||||
until: result is succeeded
|
filename: icinga
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: install packages
|
- name: Install packages
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
name:
|
name:
|
||||||
- icinga2
|
- icinga2
|
||||||
- 'icinga2-ido-{{ icinga2_db_type }}'
|
- "icinga2-ido-{{ icinga2_db_type }}"
|
||||||
- icingacli
|
- icingacli
|
||||||
- monitoring-plugins
|
- monitoring-plugins
|
||||||
retries: 2
|
- nagios-nrpe-plugin
|
||||||
register: result
|
|
||||||
until: result is succeeded
|
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: create certs directory
|
- name: Create certs directory
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /var/lib/icinga2/certs
|
path: /var/lib/icinga2/certs
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0750
|
mode: "0750"
|
||||||
state: directory
|
state: directory
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
109
tasks/config.yml
109
tasks/config.yml
|
@ -1,33 +1,34 @@
|
||||||
---
|
---
|
||||||
- name: remove old config files
|
- name: Remove old config files
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/icinga2/conf.d/apt.conf
|
path: /etc/icinga2/conf.d/apt.conf
|
||||||
state: absent
|
state: absent
|
||||||
notify: reload icinga2
|
notify: Reload icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy scripts
|
- name: Copy scripts
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: '{{ item.value }}'
|
content: "{{ item.value }}"
|
||||||
dest: '/etc/icinga2/scripts/{{ item.key }}'
|
dest: "/etc/icinga2/scripts/{{ item.key }}"
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0750
|
mode: "0750"
|
||||||
loop: '{{ icinga2_scripts|dict2items }}'
|
loop: "{{ icinga2_scripts | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: '{{ item.key }}'
|
label: "{{ item.key }}"
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy config files
|
- name: Copy config files
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: '{{ item }}.conf.j2'
|
src: "{{ item }}.conf.j2"
|
||||||
dest: '/etc/icinga2/conf.d/{{ item }}.conf'
|
dest: "/etc/icinga2/conf.d/{{ item }}.conf"
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
loop:
|
loop:
|
||||||
- check_commands
|
- check_commands
|
||||||
- commands
|
- commands
|
||||||
|
- dependencies
|
||||||
- groups
|
- groups
|
||||||
- hosts
|
- hosts
|
||||||
- notifications
|
- notifications
|
||||||
|
@ -35,95 +36,95 @@
|
||||||
- templates
|
- templates
|
||||||
- timeperiods
|
- timeperiods
|
||||||
- users
|
- users
|
||||||
notify: reload icinga2
|
notify: Reload icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy zones config files
|
- name: Copy zones config files
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: zones.conf.j2
|
src: zones.conf.j2
|
||||||
dest: /etc/icinga2/zones.conf
|
dest: /etc/icinga2/zones.conf
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
notify: reload icinga2
|
notify: Reload icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy ido config file
|
- name: Copy ido config file
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: ido-db.conf.j2
|
src: ido-db.conf.j2
|
||||||
dest: /etc/icinga2/conf.d/ido-db.conf
|
dest: /etc/icinga2/conf.d/ido-db.conf
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
notify: restart icinga2
|
notify: Restart icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy api SSL key
|
- name: Copy api SSL key
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: '{{ icinga2_api_ssl_node_key }}'
|
content: "{{ icinga2_api_ssl_node_key }}"
|
||||||
dest: '/var/lib/icinga2/certs/{{ inventory_hostname }}.key'
|
dest: "/var/lib/icinga2/certs/{{ inventory_hostname }}.key"
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
when: '"api" in icinga2_features'
|
when: "'api' in icinga2_features"
|
||||||
notify: restart icinga2
|
notify: Restart icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy api SSL certificate
|
- name: Copy api SSL certificate
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: '{{ icinga2_api_ssl_node_crt }}'
|
content: "{{ icinga2_api_ssl_node_crt }}"
|
||||||
dest: '/var/lib/icinga2/certs/{{ inventory_hostname }}.crt'
|
dest: "/var/lib/icinga2/certs/{{ inventory_hostname }}.crt"
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
when: '"api" in icinga2_features'
|
when: "'api' in icinga2_features"
|
||||||
notify: restart icinga2
|
notify: Restart icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy api SSL ca certifiacte
|
- name: Copy api SSL ca certifiacte
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: '{{ icinga2_api_ssl_ca_crt }}'
|
content: "{{ icinga2_api_ssl_ca_crt }}"
|
||||||
dest: '{{ item }}/ca.crt'
|
dest: "{{ item }}/ca.crt"
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
when: '"api" in icinga2_features'
|
when: "'api' in icinga2_features"
|
||||||
loop:
|
loop:
|
||||||
- /var/lib/icinga2/certs
|
- /var/lib/icinga2/certs
|
||||||
- /etc/icinga2/pki
|
- /etc/icinga2/pki
|
||||||
notify: restart icinga2
|
notify: Restart icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy api SSL ca key
|
- name: Copy api SSL ca key
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: '{{ icinga2_api_ssl_ca_key }}'
|
content: "{{ icinga2_api_ssl_ca_key }}"
|
||||||
dest: /etc/icinga2/pki/ca.key
|
dest: /etc/icinga2/pki/ca.key
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
when: '"api" in icinga2_features and icinga2_master'
|
when: "'api' in icinga2_features and icinga2_master"
|
||||||
notify: restart icinga2
|
notify: Restart icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: copy feature config files
|
- name: Copy feature config files
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: feature.conf.j2
|
src: feature.conf.j2
|
||||||
dest: '/etc/icinga2/features-available/{{ item.key }}.conf'
|
dest: "/etc/icinga2/features-available/{{ item.key }}.conf"
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: "0640"
|
||||||
loop: '{{ icinga2_features|dict2items }}'
|
loop: "{{ icinga2_features | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: '{{ item.key }}'
|
label: "{{ item.key }}"
|
||||||
notify: restart icinga2
|
notify: Restart icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
||||||
- name: manage features
|
- name: Manage features
|
||||||
community.general.icinga2_feature:
|
community.general.icinga2_feature:
|
||||||
name: '{{ item.key }}'
|
name: "{{ item.key }}"
|
||||||
state: '{{ item.state|default("present") }}'
|
state: "{{ item.state | default('present') }}"
|
||||||
loop: '{{ icinga2_features|dict2items }}'
|
loop: "{{ icinga2_features | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: '{{ item.key }}'
|
label: "{{ item.key }}"
|
||||||
notify: restart icinga2
|
notify: Restart icinga2
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
---
|
---
|
||||||
- import_tasks: base.yml
|
- name: Import base
|
||||||
- import_tasks: config.yml
|
ansible.builtin.import_tasks: base.yml
|
||||||
- import_tasks: service.yml
|
- name: Import config
|
||||||
|
ansible.builtin.import_tasks: config.yml
|
||||||
|
- name: Import service
|
||||||
|
ansible.builtin.import_tasks: service.yml
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
- name: enable and start service
|
- name: Enable and start service
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: icinga2
|
name: icinga2
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
{% for name, command in icinga2_check_commands.items() %}
|
{% for name, command in icinga2_check_commands.items() %}
|
||||||
|
|
||||||
object CheckCommand "{{ name }}" {
|
object CheckCommand "{{ name }}" {
|
||||||
|
{% if command.command is not string %}
|
||||||
|
command = ["{{ command.command | join('", "') }}"]
|
||||||
|
{% else %}
|
||||||
command = {{ command.command }}
|
command = {{ command.command }}
|
||||||
|
{% endif %}
|
||||||
{% if command.arguments is defined %}
|
{% if command.arguments is defined %}
|
||||||
|
|
||||||
arguments = {
|
arguments = {
|
||||||
|
@ -26,7 +29,7 @@ object CheckCommand "{{ name }}" {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if command.vars is defined %}
|
{% if command.vars is defined %}
|
||||||
|
|
||||||
var = {
|
vars = {
|
||||||
{% for var, value in command.vars.items() %}
|
{% for var, value in command.vars.items() %}
|
||||||
{{ var }} = {% if value is number %}{{ value }}{% else %}"{{ value }}"{% endif %}
|
{{ var }} = {% if value is number %}{{ value }}{% else %}"{{ value }}"{% endif %}
|
||||||
|
|
||||||
|
@ -62,7 +65,7 @@ object EventCommand "{{ name }}" {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if command.vars is defined %}
|
{% if command.vars is defined %}
|
||||||
|
|
||||||
var = {
|
vars = {
|
||||||
{% for var, value in command.vars.items() %}
|
{% for var, value in command.vars.items() %}
|
||||||
{{ var }} = {% if value is number %}{{ value }}{% else %}"{{ value }}"{% endif %}
|
{{ var }} = {% if value is number %}{{ value }}{% else %}"{{ value }}"{% endif %}
|
||||||
|
|
||||||
|
|
33
templates/dependencies.conf.j2
Normal file
33
templates/dependencies.conf.j2
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
{% for name, dependency in icinga2_dependencies.items() %}
|
||||||
|
|
||||||
|
apply Dependency "{{ name }}" to Service {
|
||||||
|
{% if dependency.parent_host_name is defined %}
|
||||||
|
{% if dependency.parent_host_name == "host.name" %}
|
||||||
|
parent_host_name = host.name
|
||||||
|
{% else %}
|
||||||
|
parent_host_name = {{ dependency.parent_host_name }}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% for option in ['parent_service_name', 'child_host_name', 'child_service_name' 'period'] %}
|
||||||
|
{% if dependency[option] is defined %}
|
||||||
|
{{ option }} = "{{ dependency[option] }}"
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% for option in ['disable_checks', 'disable_notifications', 'ignore_soft_states'] %}
|
||||||
|
{% if dependency[option] is defined %}
|
||||||
|
{{ option }} = {{ dependency[option] | ternary("true", "false") }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if dependency.states is defined %}
|
||||||
|
states = [ {{ dependency.states | join(', ') }} ]
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if dependency.assign is defined %}
|
||||||
|
assign where {{ dependency.assign }}
|
||||||
|
{% endif %}
|
||||||
|
{% if dependency.ignore is defined %}
|
||||||
|
ignore where {{ dependency.ignore }}
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
|
@ -2,7 +2,9 @@
|
||||||
{% for name, host in icinga2_hosts.items() %}
|
{% for name, host in icinga2_hosts.items() %}
|
||||||
|
|
||||||
object Host "{{ name }}" {
|
object Host "{{ name }}" {
|
||||||
|
{% if host.template is defined %}
|
||||||
import "{{ host.template }}"
|
import "{{ host.template }}"
|
||||||
|
{% endif %}
|
||||||
{% if host.address is defined %}
|
{% if host.address is defined %}
|
||||||
address = "{{ host.address }}"
|
address = "{{ host.address }}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -12,6 +14,30 @@ object Host "{{ name }}" {
|
||||||
{% if host.zone is defined %}
|
{% if host.zone is defined %}
|
||||||
zone = "{{ host.zone }}"
|
zone = "{{ host.zone }}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if host.options is defined %}
|
||||||
|
{% for var, value in host.options.items() %}
|
||||||
|
{% if value is sameas True %}
|
||||||
|
{{ var }} = true
|
||||||
|
{% elif value is sameas False %}
|
||||||
|
{{ var }} = false
|
||||||
|
{% elif value is mapping %}
|
||||||
|
{% for name, config in value.items() %}
|
||||||
|
{{ var }}["{{ name }}"] = {
|
||||||
|
{% for option, v in config.items() %}
|
||||||
|
{{ option }} = {% if v is number %}{{ v }}{% else %}"{{ v }}"{% endif %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
{% elif value is iterable and not value is string %}
|
||||||
|
{{ var }} = [ "{{ value|join('", "') }}" ]
|
||||||
|
{% elif value is number or value|regex_search('^[0-9]+(s|m|h|d)$') %}
|
||||||
|
{{ var }} = {{ value }}
|
||||||
|
{% else %}
|
||||||
|
{{ var }} = "{{ value }}"
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% if host.vars is defined %}
|
{% if host.vars is defined %}
|
||||||
|
|
||||||
{% for var, value in host.vars.items() %}
|
{% for var, value in host.vars.items() %}
|
||||||
|
@ -29,7 +55,7 @@ object Host "{{ name }}" {
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% elif value is iterable and not value is string %}
|
{% elif value is iterable and not value is string %}
|
||||||
vars.{{ var }} = [ "{{ value|join(', "') }}" ]
|
vars.{{ var }} = [ "{{ value|join('", "') }}" ]
|
||||||
{% elif value is number or value|regex_search('^[0-9]+(s|m|h|d)$') %}
|
{% elif value is number or value|regex_search('^[0-9]+(s|m|h|d)$') %}
|
||||||
vars.{{ var }} = {{ value }}
|
vars.{{ var }} = {{ value }}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -20,9 +20,27 @@ apply Service "{{ name }}" {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if service.vars is defined %}
|
{% if service.vars is defined %}
|
||||||
|
|
||||||
{% for var_name, value in service.vars.items() %}
|
{% for var, value in service.vars.items() %}
|
||||||
vars.{{ var_name }} = {% if value is number %}{{ value }}{% else %}"{{ value|replace('\n', ' ') }}"{% endif %}
|
{% if value is sameas True %}
|
||||||
|
vars.{{ var }} = true
|
||||||
|
{% elif value is sameas False %}
|
||||||
|
vars.{{ var }} = false
|
||||||
|
{% elif value is mapping %}
|
||||||
|
{% for name, config in value.items() %}
|
||||||
|
vars.{{ var }}["{{ name }}"] = {
|
||||||
|
{% for option, v in config.items() %}
|
||||||
|
{{ option }} = {% if v is number %}{{ v }}{% else %}"{{ v|replace('\n', ' ')|trim }}"{% endif %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
{% elif value is iterable and not value is string %}
|
||||||
|
vars.{{ var }} = [ "{{ value|join('", "') }}" ]
|
||||||
|
{% elif value is number or value|regex_search('^[0-9]+(s|m|h|d)$') %}
|
||||||
|
vars.{{ var }} = {{ value }}
|
||||||
|
{% else %}
|
||||||
|
vars.{{ var }} = "{{ value|replace('\n', ' ')|trim }}"
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ object UserGroup "{{ name }}" {
|
||||||
|
|
||||||
object User "{{ name }}" {
|
object User "{{ name }}" {
|
||||||
display_name = "{{ user.display_name|default(name) }}"
|
display_name = "{{ user.display_name|default(name) }}"
|
||||||
groups = [ "{{ user.groups|join(', "') }}" ]
|
groups = [ "{{ user.groups|join('", "') }}" ]
|
||||||
email = "{{ user.email }}"
|
email = "{{ user.email }}"
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -17,6 +17,6 @@ object User "{{ name }}" {
|
||||||
|
|
||||||
object ApiUser "{{ name }}" {
|
object ApiUser "{{ name }}" {
|
||||||
password = "{{ user.password }}"
|
password = "{{ user.password }}"
|
||||||
permissions = [ "{{ user.permissions|join(', "') }}" ]
|
permissions = [ "{{ user.permissions|join('", "') }}" ]
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue