Coder Social home page Coder Social logo

bodsch / ansible-icinga2 Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 6.0 503 KB

ansible role to deploy an Icinga2 master or satellite. supports HA for both components

License: BSD 2-Clause "Simplified" License

Shell 4.46% Python 73.75% Jinja 21.66% Makefile 0.13%
monitoring icinga2 ansible automation cluster icinga2-master icinga2-satellite

ansible-icinga2's Introduction

Ansible Role: icinga2

Ansible role to setup Icinga2 master or satellite.


I am in the process of transferring this role to a collection and will therefore no longer process any issues or merge requests here.
However, I will include them in the collection!
Please be patient until I have completed the work!


GitHub Workflow Status GitHub issues GitHub release (latest by date) Ansible Quality Score

Requirements & Dependencies

Ansible Collections

ansible-galaxy collection install bodsch.core

or

ansible-galaxy collection install --requirements-file collections.yml

Python Module

  • dnspython

Operating systems

Tested on

  • ArchLinux
  • Debian based
    • Debian 10 / 11
    • Ubuntu 20.04
  • RedHat based
    • Alma Linux 8
    • Rocky Linux 8
    • OracleLinux 8

Contribution

Please read Contribution

Development, Branches (Git Tags)

The master Branch is my Working Horse includes the "latest, hot shit" and can be complete broken!

If you want to use something stable, please use a Tagged Version!

Credits


Please read the following documention for configuration points.

Documentation


Examples

A complete test setup can be found in the GitLab under icinga2-infrastructure.

Icinga2 Master

single-master

---
- host: icinga-master
  vars:
    icinga2_ido:
      user: icinga2_ido
      password: icinga2_ido
      host: localhost
      cleanup:
        acknowledgements_age: 72h

    icinga2_api:
      user:
        icinga2:
          password: S0mh1TuFJI
          permissions: '*'

    icinga2_salt: 42T2fYT7bIxj5v291ajAW6kK0njvNMww8eWinBdEO5vh02xwC5qaNMMx77qNkYFE

    icinga2_masters:
      master-1.icinga.local:

    icinga2_host_object:
      master-1.icinga.local:
        endpoint_name: master-1.icinga.local
        zone: master
        display_name: master-1.icinga.local
        import: generic-host
        address: '{{ ansible_default_ipv4.address }}'
        vars: |
          os = "Linux"
          dist = "{{ ansible_distribution }}"
          dist_ver = "{{ ansible_distribution_version }}"
          disks = {
            "disk /" = {
              disk_partitions = "/"
            }
          }
          services = [ "uptime", "memory" ]

  roles:
    - role: icinga2

multi-master

---
- host: icinga-master
  vars:
    icinga2_ido:
      user: icinga2_ido
      password: icinga2_ido
      host: localhost
      cleanup:
        acknowledgements_age: 72h

    icinga2_api:
      user:
        icinga2:
          password: S0mh1TuFJI
          permissions: '*'

    icinga2_salt: 42T2fYT7bIxj5v291ajAW6kK0njvNMww8eWinBdEO5vh02xwC5qaNMMx77qNkYFE

    icinga2_ha: true

    icinga2_masters:
      master-1.icinga.local:
        # type: primary
        ip: 192.168.130.20
        port: 5665
      master-2.icinga.local:
        ip: 192.168.130.21

  roles:
    - role: icinga2

Icinga satellite

simple

---
- host: icinga-master
  vars:
    icinga2_mode: satellite

    icinga2_salt: 42T2fYT7bIxj5v291ajAW6kK0njvNMww8eWinBdEO5vh02xwC5qaNMMx77qNkYFE

    icinga2_masters:
      master-1.icinga.local:

    icinga2_host_object:

      satellite-1.icinga.local:
        endpoint_name: satellite-1.icinga.local
        zone: "{{ icinga2_satellite_zone }}"
        display_name: satellite-1.icinga.local
        import: generic-host
        address: '{{ ansible_default_ipv4.address }}'
        vars: |
          os = "Linux"
          dist = "{{ ansible_distribution }}"
          dist_ver = "{{ ansible_distribution_version }}"
          satellite = true
          disks = {
            "disk /" = {
              disk_partitions = "/"
            }
          }
          services = [ "uptime" ]

  roles:
    - role: icinga2

multi satellite with zones

---
- host: icinga-master
  vars:
    icinga2_mode: satellite

    icinga2_salt: 42T2fYT7bIxj5v291ajAW6kK0njvNMww8eWinBdEO5vh02xwC5qaNMMx77qNkYFE

    icinga2_masters:
      master-1.icinga.local:

    icinga2_satellites:
      zone1:
        satellite-1.icinga.local:
          ip: 192.168.130.30
        satellite-2.icinga.local:
          ip: 192.168.130.31

  roles:
    - role: icinga2

tests

for testing

tox -e py38-ansible29 -- molecule

tox -e py38-ansible29 -- molecule -s icinga2-satellite

Troubleshooting & Known issues

API

export CURL_OPTS="--silent --insecure"
export ICINGA_CREDS="--user icinga2:S0mh1TuFJI"
export ICINGA_API_URL="https://master-1.icinga.local:5665/v1"
$ curl ${ICINGA_CREDS} ${CURL_OPTS} --header 'Accept: application/json' ${ICINGA_API_URL}/status/ApiListener | jq --raw-output ".results[].status.api.zones"
$ curl ${ICINGA_CREDS} ${CURL_OPTS} --header 'Accept: application/json' ${ICINGA_API_URL}/status/CIB | jq --raw-output '.results[].status.uptime'
$ curl ${ICINGA_CREDS} ${CURL_OPTS} --header 'Accept: application/json' ${ICINGA_API_URL}/status/ApiListener | jq --raw-output ".results[].status.api"
$ curl ${ICINGA_CREDS} ${CURL_OPTS} ${ICINGA_API_URL}/objects/hosts | jq
$ curl ${ICINGA_CREDS} ${CURL_OPTS} --header 'Accept: application/json' --header 'X-HTTP-Method-Override: GET' --request POST --data '{ "attrs": [ "name" ], "type": "Host", "filter": "host.name==\"master-1.icinga.local\"" }' ${ICINGA_API_URL}/objects/hosts

License

BSD 2-clause

ansible-icinga2's People

Contributors

bodsch avatar ekartsonakis avatar jofiedler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ansible-icinga2's Issues

Failing on task detect mysql ido version on second run

SUMMARY

After the first run, when create the mysql ido schema successfully created ido DB schema, if we run again the role it is failing on task: detect mysql ido version with error.

STEPS TO REPRODUCE
Re-run the role on the same host
EXPECTED RESULTS
Detect mysql ido version and register the value for the next task
ACTUAL RESULTS
TASK [ansible-icinga2 : detect mysql ido version] **************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: too many values to unpack (expected 2)
fatal: [f6t-mon-001]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "<stdin>", line 107, in <module>
      File "<stdin>", line 99, in _ansiballz_main
      File "<stdin>", line 47, in invoke_module
      File "/usr/lib/python3.9/runpy.py", line 210, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_icinga2_ido_version_payload_5ot7egot/ansible_icinga2_ido_version_payload.zip/ansible/modules/icinga2_ido_version.py", line 204, in <module>
      File "/tmp/ansible_icinga2_ido_version_payload_5ot7egot/ansible_icinga2_ido_version_payload.zip/ansible/modules/icinga2_ido_version.py", line 195, in main
      File "/tmp/ansible_icinga2_ido_version_payload_5ot7egot/ansible_icinga2_ido_version_payload.zip/ansible/modules/icinga2_ido_version.py", line 72, in run
    ValueError: too many values to unpack (expected 2)
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1
ENVIRONMENT

ansible host: ansible [core 2.13.5]
target host OS: Debian 11.5
target host installed ido utils version: 1.15.1
target host installed MariaDB version: 10.6.11

satellite deployment cannot restart icinga2 due to missing configuration file

SUMMARY

ERROR! The requested handler 'restart icinga2 master' was not found in either the main handlers list nor in the listening handlers list

Check on satellite host:
icinga2 daemon -C
[2021-03-08 15:53:52 +0100] information/cli: Icinga application loader (version: 2.12.3)
[2021-03-08 15:53:52 +0100] information/cli: Loading configuration file(s).
[2021-03-08 15:53:52 +0100] critical/config: Error: Include file 'global-templates.conf' does not exist
Location: in /etc/icinga2/icinga2.conf: 5:1-5:31
/etc/icinga2/icinga2.conf(3): include "constants.conf"
/etc/icinga2/icinga2.conf(4):
/etc/icinga2/icinga2.conf(5): include "global-templates.conf"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/icinga2.conf(6): // The zones.conf defines zones for a cluster setup
/etc/icinga2/icinga2.conf(7): include "zones.conf"

[2021-03-08 15:53:52 +0100] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.

STEPS TO REPRODUCE
- hosts: icinga2_agents
  gather_facts: true
  become: true
  roles:
    - role: monitoring-plugins-role
    - role: icinga2-role
  tags: icinga-agents
EXPECTED RESULTS

ACTUAL RESULTS

ENVIRONMENT

centos 8

task "icinga2 : detect icinga2_user"

Version: latest

OS: ArchLinux

TASK [icinga2 : detect icinga2_user] *******************************************
task path: /home/bodsch/.cache/molecule/ansible-icingaweb2/default/roles/icinga2/tasks/install.yml:114
redirecting (type: connection) ansible.builtin.docker to community.general.docker
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IndexError: list index out of range
fatal: [icinga2]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "/root/.ansible/tmp/ansible-tmp-1634794631.569584-13069-89262462566020/AnsiballZ_icinga2_prepared_vars.py", line 102, in <module>
        _ansiballz_main()
      File "/root/.ansible/tmp/ansible-tmp-1634794631.569584-13069-89262462566020/AnsiballZ_icinga2_prepared_vars.py", line 94, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/root/.ansible/tmp/ansible-tmp-1634794631.569584-13069-89262462566020/AnsiballZ_icinga2_prepared_vars.py", line 40, in invoke_module
        runpy.run_module(mod_name='ansible.modules.icinga2_prepared_vars', init_globals=None, run_name='__main__', alter_sys=True)
      File "/usr/lib/python3.9/runpy.py", line 210, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_icinga2_prepared_vars_payload_c7895z_9/ansible_icinga2_prepared_vars_payload.zip/ansible/modules/icinga2_prepared_vars.py", line 77, in <module>
      File "/tmp/ansible_icinga2_prepared_vars_payload_c7895z_9/ansible_icinga2_prepared_vars_payload.zip/ansible/modules/icinga2_prepared_vars.py", line 68, in main
      File "/tmp/ansible_icinga2_prepared_vars_payload_c7895z_9/ansible_icinga2_prepared_vars_payload.zip/ansible/modules/icinga2_prepared_vars.py", line 43, in run
    IndexError: list index out of range
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

PLAY RECAP *********************************************************************

Deployment of multiple satellites/agents, restart master fails

Hi Bodo, when deploying multiple satellites/agents with ansible, the processing is done in parallel. At the end each one tries to restart the master, only the first one succeeds and then the error message appears:
"ERROR! The requested handler 'restart icinga2 master' was not found in either the main handlers list nor in the listening handlers list".

AttributeError: 'NoneType' object has no attribute 'group' in icinga2_version.py

SUMMARY

AttributeError: 'NoneType' object has no attribute 'group' in icinga2_version.py while running playbook for incina master installation.
Error in the current version. In version 1.2.2 this error does not occur

STEPS TO REPRODUCE
  gather_facts: true
  become: true
  roles:

    - role: monitoring-plugins-role
    - role: mariadb-role

    - role: icinga2-role
      tags: icinga2-role-server

    - role: nginx-role
    - role: php-role
    - role: icingaweb2-role
  tags: icinga-master

EXPECTED RESULTS

ACTUAL RESULTS

ENVIRONMENT

icinga2 - The Icinga 2 network monitoring daemon (version: 2.12.3)

oraclelinux has no yum anymore

TASK [bodsch.icinga2 : update rpm cache] ***************************************
  fatal: [instance]: FAILED! => changed=false 
    cmd: yum clean metadata
    msg: '[Errno 2] No such file or directory: b''yum'': b''yum'''
    rc: 2

BUG at "apply Notification"

validate input!

[2022-03-23 20:23:35 +0100] critical/config: Error: Validation failed for object 'icinga.boone-schulz.de!procs!service-mail' of type 'Notification': Validation failed: No users/user_groups specified.
Location: in /etc/icinga2/notifications/notification-apply-rules.conf: 11:1-11:44
/etc/icinga2/notifications/notification-apply-rules.conf(9): }
/etc/icinga2/notifications/notification-apply-rules.conf(10): 
/etc/icinga2/notifications/notification-apply-rules.conf(11): apply Notification "service-mail" to Service {
                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/notifications/notification-apply-rules.conf(12):   import "generic-service-notification"
/etc/icinga2/notifications/notification-apply-rules.conf(13):   interval  = 2h

ansible_default_ipv4.address undefined in docker ubuntu

TASK [bodsch.icinga2 : create hosts.conf] **************************************
  fatal: [instance]: FAILED! => changed=false 
    msg: 'AnsibleUndefinedVariable: {''localhost'': {''import'': ''generic-host'', ''address'': ''{{ ansible_default_ipv4.address }}'', ''display_name'': ''{{ ansible_fqdn }}'', ''vars'': ''os = "Linux"\ndist = "{{ ansible_distribution }}"\ndist_ver = "{{ ansible_distribution_version }}"\ndisks = {\n  "disk /" = {\n    disk_partitions = "/"\n  }\n}\n''}}: ''ansible_default_ipv4'' is undefined'

''ansible_default_ipv4'' is undefined'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.