From ea459fbc5e72d83077aeab1b9296cfe0aa97c2f3 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Mon, 28 Jul 2025 11:50:49 +1200 Subject: [PATCH 1/3] nagios: make services param a list --- plugins/modules/nagios.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/modules/nagios.py b/plugins/modules/nagios.py index 830a805f87..17b079c48c 100644 --- a/plugins/modules/nagios.py +++ b/plugins/modules/nagios.py @@ -90,7 +90,8 @@ options: services running on it.) To schedule downtime for all O(services) on particular host use keyword V(all), for example O(services=all). aliases: ["service"] - type: str + type: list + elements: str servicegroup: description: - The Servicegroup we want to set downtimes/alerts for. @@ -324,7 +325,7 @@ def main(): start=dict(type='str'), minutes=dict(type='int', default=30), cmdfile=dict(type='str', default=which_cmdfile()), - services=dict(type='str', aliases=['service']), + services=dict(type='list', elements='str', aliases=['service']), command=dict(type='str'), ), required_if=[ @@ -382,10 +383,12 @@ class Nagios(object): self.cmdfile = kwargs['cmdfile'] self.command = kwargs['command'] - if (kwargs['services'] is None) or (kwargs['services'] == 'host') or (kwargs['services'] == 'all'): + if kwargs['services'] is None : self.services = kwargs['services'] + elif len(kwargs['services']) == 1 and kwargs['services'][0] in ['host', 'all']: + self.services = kwargs['services'][0] else: - self.services = kwargs['services'].split(',') + self.services = kwargs['services'] self.command_results = [] @@ -1243,14 +1246,9 @@ class Nagios(object): elif self.action == 'unsilence_nagios': self.unsilence_nagios() - elif self.action == 'command': + else: # self.action == 'command' self.nagios_cmd(self.command) - # wtf? - else: - self.module.fail_json(msg="unknown action specified: '%s'" % - self.action) - self.module.exit_json(nagios_commands=self.command_results, changed=True) From fa857569857eaf65b38635c3320ff108bc18287a Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Mon, 28 Jul 2025 11:55:21 +1200 Subject: [PATCH 2/3] add changelog frag --- changelogs/fragments/10493-nagios-services.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/10493-nagios-services.yml diff --git a/changelogs/fragments/10493-nagios-services.yml b/changelogs/fragments/10493-nagios-services.yml new file mode 100644 index 0000000000..3a04556c68 --- /dev/null +++ b/changelogs/fragments/10493-nagios-services.yml @@ -0,0 +1,2 @@ +minor_changes: + - nagios - make parameter ``services`` a ``list`` instead of a ``str`` (https://github.com/ansible-collections/community.general/pull/10493). From 3b755fead33e994f19ffea69730b27de8bb78723 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Mon, 28 Jul 2025 20:45:00 +1200 Subject: [PATCH 3/3] nagios: update docs --- plugins/modules/nagios.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/nagios.py b/plugins/modules/nagios.py index 17b079c48c..6426975546 100644 --- a/plugins/modules/nagios.py +++ b/plugins/modules/nagios.py @@ -83,12 +83,14 @@ options: description: - What to manage downtime/alerts for. Separate multiple services with commas. - 'B(Required) option when O(action) is one of: V(downtime), V(acknowledge), V(forced_check), V(enable_alerts), V(disable_alerts).' - - You can specify multiple services at once by separating them with commas, for example O(services=httpd,nfs,puppet). - When specifying what O(services) to handle there is a special service value, V(host), which handles alerts/downtime/acknowledge for the I(host itself), for example O(services=host). This keyword may not be given with other services at the same time. B(Setting alerts/downtime/acknowledge for a host does not affect alerts/downtime/acknowledge for any of the services running on it.) To schedule downtime for all O(services) on particular host use keyword V(all), for example O(services=all). + - Before community.general 11.2.0, one could specify multiple services at once by separating them with commas, for example + O(services=httpd,nfs,puppet). Since community.general 11.2.0, there can be spaces around the commas, and an actual + list can be provided. aliases: ["service"] type: list elements: str @@ -224,7 +226,9 @@ EXAMPLES = r""" - name: Disable httpd and nfs alerts community.general.nagios: action: disable_alerts - service: httpd,nfs + service: + - httpd + - nfs host: '{{ inventory_hostname }}' - name: Disable HOST alerts