Commit 0fd8afea authored by Ross Barnie's avatar Ross Barnie Committed by aflatto

i2_constants refactor (#13)

* Add ability to manage icinga2.conf

* Enable management of constants.conf

closes #9

* Update README.md

* Cleanup test.yml

* Refactor i2_const_* vars to i2_constants dict

Using the combine filter, we can remove the `i2_const_*` variables and
have a generic `i2_constants` dictionary from which we can read the
user-specified constants (`i2_custom_constants`) and our defaults
(`i2_default_constants`). We lose the comments in the process however.

* Copy constants file before overriding OS defaults
parent 59b9fdee
...@@ -60,13 +60,7 @@ You may choose to use your own or the systems default repositories. Repository m ...@@ -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_i2_yum_url](#variable-i2_yum_url)
- [Variable: i2_confd](#variable-i2_confd) - [Variable: i2_confd](#variable-i2_confd)
- [Variable: i2_include_plugins](#variable-i2_include_plugins) - [Variable: i2_include_plugins](#variable-i2_include_plugins)
- [Variable: i2_const_plugindir](#variable-i2_const_plugindir) - [Variable: i2_custom_constants](#variable-i2_custom_constants)
- [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) - [**Variables system specific](#variables-os-specific)
- [Variable: i2_conf_dir](#variable-i2_conf_dir) - [Variable: i2_conf_dir](#variable-i2_conf_dir)
- [Variable: i2_user](#variable-i2_user) - [Variable: i2_user](#variable-i2_user)
...@@ -131,17 +125,29 @@ Set `ZoneName` constant. Defaults to `{{ ansible_fqdn }}`. ...@@ -131,17 +125,29 @@ Set `ZoneName` constant. Defaults to `{{ ansible_fqdn }}`.
#### Variable: `i2_const_ticketsalt` #### Variable: `i2_const_ticketsalt`
Set `TicketSalt` constant. Empty by default. Set `TicketSalt` constant. Empty by default.
#### Variable: `i2_constants` #### Variable: `i2_custom_constants`
Add custom constants to `constants.conf`. Must be a dictionary. 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 ```yaml
vars: vars:
- i2_constants: - i2_constants:
foo: "bar" TicketSalt: "My ticket salt"
Foo: "bar"
``` ```
### Variables system specific ### Variables system specific
The following variables are system specific and don't need to be overwritten in most cases. Be careful when making 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. changes to any of these variables.
......
...@@ -15,10 +15,4 @@ i2_include_plugins: ...@@ -15,10 +15,4 @@ i2_include_plugins:
- "manubulon" - "manubulon"
- "windows-plugins" - "windows-plugins"
- "nscp" - "nscp"
i2_const_plugindir: "{{ i2_lib_dir }}/nagios/plugins" i2_custom_constants: {}
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: {}
...@@ -18,6 +18,22 @@ ...@@ -18,6 +18,22 @@
mode: 0644 mode: 0644
notify: reload icinga2 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 - name: Manage Icinga 2 constants
become: yes become: yes
template: template:
......
...@@ -5,32 +5,6 @@ ...@@ -5,32 +5,6 @@
* the other configuration files. * 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() %} {% for name, value in i2_constants.items() %}
const {{ name }} = "{{ value }}"" const {{ name }} = "{{ value }}"
{% endfor %} {% endfor %}
--- ---
i2_conf_dir: "/etc/icinga2" 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) }}"
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