From 848d368697cf5548a0b89b0077c66eb3017c4384 Mon Sep 17 00:00:00 2001 From: Gianmarco Mameli <57061995+gianmarco-mameli@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:53:46 +0100 Subject: [PATCH] Add vars parameter to notification templates, task icinga_serviceset swap (#271) * done * fix version * removed version added from vars --- docs/icinga_notification_template.rst | 8 +++++++- examples/icinga_notification_template.yml | 4 ++++ plugins/modules/icinga_notification_template.py | 11 +++++++++++ .../tasks/icinga_notification_template.yml | 1 + roles/ansible_icinga/tasks/main.yml | 10 +++++----- .../tasks/absent_icinga_notification_template.yml | 4 ++++ .../icinga/tasks/icinga_notification_template.yml | 4 ++++ .../tasks/wrong_host_icinga_notification_template.yml | 4 ++++ .../tasks/wrong_pass_icinga_notification_template.yml | 4 ++++ 9 files changed, 44 insertions(+), 6 deletions(-) diff --git a/docs/icinga_notification_template.rst b/docs/icinga_notification_template.rst index 9f503553..8f69dfa9 100644 --- a/docs/icinga_notification_template.rst +++ b/docs/icinga_notification_template.rst @@ -75,6 +75,8 @@ Parameters user_groups (optional, list, None) User Groups that should be notified by this notification. + vars (optional, dict, {}) + Custom properties of the notification. append (optional, bool, None) Do not overwrite the whole object but instead append the defined properties. @@ -169,7 +171,7 @@ Examples .. code-block:: yaml+jinja - + - name: Create notification template telekom_mms.icinga_director.icinga_notification_template: state: present @@ -191,6 +193,8 @@ Examples - "rb" user_groups: - "OnCall" + vars: + foo: bar zone: "foozone" - name: Update notification template @@ -201,6 +205,8 @@ Examples url_password: "{{ icinga_pass }}" object_name: foonotificationtemplate notification_interval: '0' + vars: + foo: bar append: true diff --git a/examples/icinga_notification_template.yml b/examples/icinga_notification_template.yml index bf8200d2..b06a504b 100644 --- a/examples/icinga_notification_template.yml +++ b/examples/icinga_notification_template.yml @@ -20,6 +20,8 @@ - "rb" user_groups: - "OnCall" + vars: + foo: bar zone: "foozone" - name: Update notification template telekom_mms.icinga_director.icinga_notification_template: @@ -29,4 +31,6 @@ url_password: "{{ icinga_pass }}" object_name: foonotificationtemplate notification_interval: '0' + vars: + foo: bar append: true diff --git a/plugins/modules/icinga_notification_template.py b/plugins/modules/icinga_notification_template.py index 0f230733..e238a9b6 100644 --- a/plugins/modules/icinga_notification_template.py +++ b/plugins/modules/icinga_notification_template.py @@ -115,6 +115,11 @@ - Required if I(state) is C(present). type: "list" elements: str + vars: + description: + - Custom properties of the notification. + type: "dict" + default: {} """ EXAMPLES = """ @@ -139,6 +144,8 @@ - "rb" user_groups: - "OnCall" + vars: + foo: bar zone: "foozone" - name: Update notification template @@ -149,6 +156,8 @@ url_password: "{{ icinga_pass }}" object_name: foonotificationtemplate notification_interval: '0' + vars: + foo: bar append: true """ @@ -185,6 +194,7 @@ def main(): command=dict(required=False, aliases=["notification_command"]), users=dict(type="list", elements="str", required=False), user_groups=dict(type="list", elements="str", required=False), + vars=dict(type="dict", default={}, required=False), ) # Define the main module @@ -206,6 +216,7 @@ def main(): "command", "users", "user_groups", + "vars" ] data = {} diff --git a/roles/ansible_icinga/tasks/icinga_notification_template.yml b/roles/ansible_icinga/tasks/icinga_notification_template.yml index 1692948e..a28e60a8 100644 --- a/roles/ansible_icinga/tasks/icinga_notification_template.yml +++ b/roles/ansible_icinga/tasks/icinga_notification_template.yml @@ -21,6 +21,7 @@ user_groups: "{{ notification_template.user_groups | default(omit) }}" notification_command: "{{ notification_template.notification_command | default(omit) }}" imports: "{{ notification_template.imports | default(omit) }}" + vars: "{{ notification_template.vars | default(omit) }}" zone: "{{ notification_template.zone | default(omit) }}" retries: 3 delay: 3 diff --git a/roles/ansible_icinga/tasks/main.yml b/roles/ansible_icinga/tasks/main.yml index aa30bf14..6016d5f8 100644 --- a/roles/ansible_icinga/tasks/main.yml +++ b/roles/ansible_icinga/tasks/main.yml @@ -69,16 +69,16 @@ when: icinga_servicegroups is defined tags: servicegroup -- name: Icinga service configuration - ansible.builtin.include_tasks: icinga_service.yml - when: icinga_services is defined - tags: service - - name: Icinga serviceset configuration ansible.builtin.include_tasks: icinga_serviceset.yml when: icinga_servicesets is defined tags: serviceset +- name: Icinga service configuration + ansible.builtin.include_tasks: icinga_service.yml + when: icinga_services is defined + tags: service + - name: Icinga notification template configuration ansible.builtin.include_tasks: icinga_notification_template.yml when: icinga_notification_templates is defined diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_notification_template.yml b/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_notification_template.yml index f95a6484..7dfd873a 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_notification_template.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_notification_template.yml @@ -20,6 +20,8 @@ - "rb" user_groups: - "OnCall" + vars: + foo: bar zone: "foozone" - name: Update notification template telekom_mms.icinga_director.icinga_notification_template: @@ -29,4 +31,6 @@ url_password: "{{ icinga_pass }}" object_name: foonotificationtemplate notification_interval: '0' + vars: + foo: bar append: true diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/icinga_notification_template.yml b/tests/integration/targets/icinga/roles/icinga/tasks/icinga_notification_template.yml index bf8200d2..b06a504b 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/icinga_notification_template.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/icinga_notification_template.yml @@ -20,6 +20,8 @@ - "rb" user_groups: - "OnCall" + vars: + foo: bar zone: "foozone" - name: Update notification template telekom_mms.icinga_director.icinga_notification_template: @@ -29,4 +31,6 @@ url_password: "{{ icinga_pass }}" object_name: foonotificationtemplate notification_interval: '0' + vars: + foo: bar append: true diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_notification_template.yml b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_notification_template.yml index 2db00009..cf4d1517 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_notification_template.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_notification_template.yml @@ -20,6 +20,8 @@ - "rb" user_groups: - "OnCall" + vars: + foo: bar zone: "foozone" ignore_errors: true register: result @@ -36,6 +38,8 @@ url_password: "{{ icinga_pass }}" object_name: foonotificationtemplate notification_interval: '0' + vars: + foo: bar append: true ignore_errors: true register: result diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_notification_template.yml b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_notification_template.yml index cd1392ed..4abff511 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_notification_template.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_notification_template.yml @@ -20,6 +20,8 @@ - "rb" user_groups: - "OnCall" + vars: + foo: bar zone: "foozone" ignore_errors: true register: result @@ -36,6 +38,8 @@ url_password: iamwrong object_name: foonotificationtemplate notification_interval: '0' + vars: + foo: bar append: true ignore_errors: true register: result