diff --git a/README.md b/README.md index 4a5623d..3450ba0 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,7 @@ You may choose to use your own or the systems default repositories. Repository m - [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) + - [Variable: i2_custom_constants](#variable-i2_custom_constants) - [**Variables system specific](#variables-os-specific) - [Variable: i2_conf_dir](#variable-i2_conf_dir) - [Variable: i2_user](#variable-i2_user) @@ -131,17 +125,29 @@ 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. +#### Variable: `i2_custom_constants` +Add custom constants to `constants.conf`. Must be a dictionary. Defaults to: `{}` -Example: +Some default required values are specified in `i2_default_constants` and merged with this variable. Use this variable to override these default values, or add your own constants. + +Default values of `i2_default_constants`: +```yaml + PluginDir: "{{ i2_lib_dir }}/nagios/plugins" + ManubulonPluginDir: "{{ i2_lib_dir }}/nagios/plugins" + PluginContribDir: "{{ i2_lib_dir }}/nagios/plugins" + NodeName: "{{ ansible_fqdn }}" + ZoneName: "{{ ansible_fqdn }}" + TicketSalt: "" +``` + +Example usage: ```yaml vars: - i2_constants: - foo: "bar" + TicketSalt: "My ticket salt" + 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. diff --git a/defaults/main.yml b/defaults/main.yml index c0a280f..03b5542 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,10 +15,4 @@ i2_include_plugins: - "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: {} +i2_custom_constants: {} diff --git a/tasks/icinga2-config.yml b/tasks/icinga2-config.yml index 115a827..9bc7273 100644 --- a/tasks/icinga2-config.yml +++ b/tasks/icinga2-config.yml @@ -18,6 +18,22 @@ mode: 0644 notify: reload icinga2 +- name: Check for constants sample file + stat: + path: "{{ i2_conf_dir }}/constants.conf-sample" + register: sample_file + +- name: Copy original Icinga 2 config to sample + become: yes + copy: + remote_src: true + src: "{{ i2_conf_dir }}/constants.conf" + dest: "{{ i2_conf_dir }}/constants.conf-sample" + owner: "{{ i2_user }}" + group: "{{ i2_group }}" + mode: 0644 + when: not sample_file.stat.exists + - name: Manage Icinga 2 constants become: yes template: diff --git a/templates/constants.conf.j2 b/templates/constants.conf.j2 index 3bfa5e8..8ca0e87 100644 --- a/templates/constants.conf.j2 +++ b/templates/constants.conf.j2 @@ -5,32 +5,6 @@ * 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 }}"" +const {{ name }} = "{{ value }}" {% endfor %} diff --git a/vars/main.yml b/vars/main.yml index 915679d..112b021 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,10 @@ --- i2_conf_dir: "/etc/icinga2" +i2_default_constants: + PluginDir: "{{ i2_lib_dir }}/nagios/plugins" + ManubulonPluginDir: "{{ i2_lib_dir }}/nagios/plugins" + PluginContribDir: "{{ i2_lib_dir }}/nagios/plugins" + NodeName: "{{ ansible_fqdn }}" + ZoneName: "{{ ansible_fqdn }}" + TicketSalt: "" +i2_constants: "{{ i2_default_constants | combine(i2_custom_constants) }}"