Commit 59b9fdee authored by Blerim Sheqa's avatar Blerim Sheqa Committed by aflatto

Feature/main configuration (#11)

* Add ability to manage icinga2.conf

* Enable management of constants.conf
parent 74a5d499
......@@ -58,8 +58,23 @@ You may choose to use your own or the systems default repositories. Repository m
- [Variable: i2_apt_url](#variable-i2_apt_url)
- [Variable: i2_i2_yum_key](#variable-i2_yum_key)
- [Variable: i2_i2_yum_url](#variable-i2_yum_url)
- [Variable: i2_confd](#variable-i2_confd)
- [Variable: i2_include_plugins](#variable-i2_include_plugins)
- [Variable: i2_const_plugindir](#variable-i2_const_plugindir)
- [Variable: i2_const_manubulonplugindir](#variable-i2_const_manubulonplugindir)
- [Variable: i2_const_plugincontribdir](#variable-i2_const_plugincontribdir)
- [Variable: i2_const_nodename](#variable-i2_const_nodename)
- [Variable: i2_const_zonename](#variable-i2_const_zonename)
- [Variable: i2_const_ticketsalt](#variable-i2_const_ticketsalt)
- [Variable: i2_constants](#variable-i2_constants)
- [**Variables system specific](#variables-os-specific)
- [Variable: i2_conf_dir](#variable-i2_conf_dir)
- [Variable: i2_user](#variable-i2_user)
- [Variable: i2_group](#variable-i2_group)
- [Variable: i2_lib_dir](#variable-i2_lib_dir)
- [**Handlers**](#handlers)
- [Handler: start icinga2](#handler-start-icinga2)
- [Handler: reload icinga2](#handler-reload-icinga2)
### Variables
......@@ -89,12 +104,70 @@ GPG key used to verify packages on YUM based sytems. The key URL will be added t
Repository URL for YUM based sytem. Defaults to `http://packages.icinga.com/epel/$releasever/release/`. This may be
customized if you have a local mirror.
#### Variable: `i2_confd`
By default configuration located in `/etc/icinga2/conf.d` is included. This directory this directory may be change.
Defaults to `confd.`.
#### Variable: `i2_include_plugins`
The [ITL](https://www.icinga.com/docs/icinga2/latest/doc/10-icinga-template-library/) comes with a set of
pre-configured check commands. This variable defines what to include. Defaults to
`["itl", "plugins", "plugins-contrib", "manubulon", "windows-plugins", "nscp"]`
#### Variable: `i2_const_plugindir`
Set `PluginDir` constant. Deafults to `{{ i2_lib_dir }}/nagios/plugins`.
#### Variable: `i2_const_manubulonplugindir`
Set `ManubulonPluginDir` constant. Defaults to `{{ i2_lib_dir }}/nagios/plugins`.
#### Variable: `i2_const_plugincontribdir`
Set `PluginContribDir` constant. Defualts to `{{ i2_lib_dir }}/nagios/plugins`.
#### Variable: `i2_const_nodename`
Set `NodeName` constant. Defaults to `{{ ansible_fqdn }}`.
#### Variable: `i2_const_zonename`
Set `ZoneName` constant. Defaults to `{{ ansible_fqdn }}`.
#### Variable: `i2_const_ticketsalt`
Set `TicketSalt` constant. Empty by default.
#### Variable: `i2_constants`
Add custom constants to `constants.conf`. Must be a dictionary.
Example:
```yaml
vars:
- i2_constants:
foo: "bar"
```
### Variables system specific
The following variables are system specific and don't need to be overwritten in most cases. Be careful when making
changes to any of these variables.
#### Variable: `i2_conf_dir`
Base Icinga 2 configuration directory. Defaults to `/etc/icinga2`.
#### Variable: `i2_user`
Icinga 2 running as user. Default depends on OS.
#### Variable: `i2_group`
Icinga 2 running as group. Default depends on OS.
#### Variable: `i2_lib_dir`
Lib dir. Default depends on OS.
### Handlers
#### Handler: `start icinga2`
This handler starts Icinga 2. It is only used to make sure Icinga 2 is running. You can prevent this handler from
being triggerd by setting `i2_manage_service` to false.
#### Handler: `reload icinga2`
This handler reloads Icinga 2 when configuration changes. You can prevent this handler from being triggerd by setting
`i2_manage_service` to false.
## Development
A roadmap of this project is located at https://github.com/Icinga/ansible-icinga2/milestones. Please consider this
roadmap when you start contributing to the project.
......
......@@ -6,3 +6,19 @@ i2_yum_key: "https://packages.icinga.com/icinga.key"
i2_yum_url: "http://packages.icinga.com/epel/$releasever/release/"
i2_manage_package: true
i2_manage_service: true
i2_confd:
- "conf.d"
i2_include_plugins:
- "itl"
- "plugins"
- "plugins-contrib"
- "manubulon"
- "windows-plugins"
- "nscp"
i2_const_plugindir: "{{ i2_lib_dir }}/nagios/plugins"
i2_const_manubulonplugindir: "{{ i2_lib_dir }}/nagios/plugins"
i2_const_plugincontribdir: "{{ i2_lib_dir }}/nagios/plugins"
i2_const_nodename: "{{ ansible_fqdn }}"
i2_const_zonename: "{{ ansible_fqdn }}"
i2_const_ticketsalt: ""
i2_constants: {}
---
- name: start icinga2
become: yes
service:
......@@ -7,3 +6,10 @@
state: started
enabled: yes
when: i2_manage_service
- name: reload icinga2
become: yes
service:
name: icinga2
state: reloaded
when: i2_manage_service
---
galaxy_info:
author: "Icinga Development Team <info@icinga.com>"
description: "Install and configure Icinga 2"
......
---
- name: Debian - Install apt-transport-https
become: yes
apt:
......
---
- name: RedHat - Add Icinga 2 repository
become: yes
yum_repository:
......
---
- name: Create conf.d directory
become: yes
file:
dest: "{{ i2_conf_dir }}/{{ item }}"
state: directory
owner: "{{ i2_user }}"
group: "{{ i2_group }}"
with_items: "{{ i2_confd }}"
- name: Manage main Icinga 2 configuration
become: yes
template:
src: icinga2.conf.j2
dest: "{{ i2_conf_dir }}/icinga2.conf"
owner: "{{ i2_user }}"
group: "{{ i2_group }}"
mode: 0644
notify: reload icinga2
- name: Manage Icinga 2 constants
become: yes
template:
src: constants.conf.j2
dest: "{{ i2_conf_dir }}/constants.conf"
owner: "{{ i2_user }}"
group: "{{ i2_group }}"
mode: 0644
notify: reload icinga2
---
- name: Include specific Icinga 2
include: icinga2-Debian.yml
when: ansible_os_family == 'Debian'
......
---
- name: Include OS specific vars
include_vars: "{{ansible_os_family}}.yml"
- name: include icinga2.yml
include: icinga2.yml
tags:
- install
- name: include icinga2-config.yml
include: icinga2-config.yml
tags:
- config
- name: Make sure Icinga 2 is started
service:
name: icinga2
......
// {{ ansible_managed }}
/**
* This file defines global constants which can be used in
* the other configuration files.
*/
/* The directory which contains the plugins from the Monitoring Plugins project. */
const PluginDir = "{{ i2_const_plugindir }}"
/* The directory which contains the Manubulon plugins.
* Check the documentation, chapter "SNMP Manubulon Plugin Check Commands", for details.
*/
const ManubulonPluginDir = "{{ i2_const_manubulonplugindir }}"
/* The directory which you use to store additional plugins which ITL provides user contributed command definitions for.
* Check the documentation, chapter "Plugins Contribution", for details.
*/
const PluginContribDir = "{{ i2_const_plugincontribdir }}"
/* Our local instance name. By default this is the server's hostname as returned by `hostname --fqdn`.
* This should be the common name from the API certificate.
*/
const NodeName = "{{ i2_const_nodename }}"
/* Our local zone name. */
const ZoneName = "{{ i2_const_zonename }}"
/* Secret key for remote node tickets */
const TicketSalt = "{{ i2_const_ticketsalt }}"
/* Additional Constants */
{% for name, value in i2_constants.items() %}
const {{ name }} = "{{ value }}""
{% endfor %}
// {{ ansible_managed }}
/**
* Icinga 2 configuration file
* - this is where you define settings for the Icinga application including
* which hosts/services to check.
*
* For an overview of all available configuration options please refer
* to the documentation that is distributed as part of Icinga 2.
*/
/**
* The constants.conf defines global constants.
*/
include "constants.conf"
/**
* The zones.conf defines zones for a cluster setup.
* Not required for single instance setups.
*/
include "zones.conf"
/**
* The Icinga Template Library (ITL) provides a number of useful templates
* and command definitions.
* Common monitoring plugin command definitions are included separately.
*/
{% for plugins in i2_include_plugins %}
include <{{ plugins }}>
{% endfor %}
/**
* The features-available directory contains a number of configuration
* files for features which can be enabled and disabled using the
* icinga2 feature enable / icinga2 feature disable CLI commands.
* These commands work by creating and removing symbolic links in
* the features-enabled directory.
*/
include "features-enabled/*.conf"
/**
* Although in theory you could define all your objects in this file
* the preferred way is to create separate directories and files in the conf.d
* directory. Each of these files must have the file extension ".conf".
*/
{% for include_dir in i2_confd %}
include_recursive "{{ include_dir }}"
{% endfor %}
---
- hosts: all
remote_user: root
roles:
......
---
i2_user: nagios
i2_group: nagios
i2_lib_dir: /usr/lib
---
i2_user: icinga
i2_group: icinga
i2_lib_dir: /usr/lib64
---
# vars file for icinga2
i2_conf_dir: "/etc/icinga2"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment