From faf50dbace25d0236f8019d114c214c61fff3f55 Mon Sep 17 00:00:00 2001 From: Klaas Demter Date: Sat, 6 Jul 2019 22:37:23 +0200 Subject: [PATCH] Fix nagios module to recognize if file exists and is fifo pipe (#58569) add felixfontein suggestion to changelogs/fragments/58569-nagios-fifo-fix.yaml Co-Authored-By: Felix Fontein --- changelogs/fragments/58569-nagios-fifo-fix.yaml | 2 ++ lib/ansible/modules/monitoring/nagios.py | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 changelogs/fragments/58569-nagios-fifo-fix.yaml diff --git a/changelogs/fragments/58569-nagios-fifo-fix.yaml b/changelogs/fragments/58569-nagios-fifo-fix.yaml new file mode 100644 index 00000000000..db021cf519f --- /dev/null +++ b/changelogs/fragments/58569-nagios-fifo-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - nagios module - Fix nagios module to recognize if ``cmdfile`` exists and is fifo pipe. diff --git a/lib/ansible/modules/monitoring/nagios.py b/lib/ansible/modules/monitoring/nagios.py index 0bffdca9e70..24cade85c90 100644 --- a/lib/ansible/modules/monitoring/nagios.py +++ b/lib/ansible/modules/monitoring/nagios.py @@ -196,6 +196,7 @@ EXAMPLES = ''' import types import time import os.path +import stat from ansible.module_utils.basic import AnsibleModule @@ -389,6 +390,12 @@ class Nagios(object): Write the given command to the Nagios command file """ + if not os.path.exists(self.cmdfile): + self.module.fail_json(msg='nagios command file does not exist', + cmdfile=self.cmdfile) + if not stat.S_ISFIFO(os.stat(self.cmdfile).st_mode): + self.module.fail_json(msg='nagios command file is not a fifo file', + cmdfile=self.cmdfile) try: fp = open(self.cmdfile, 'w') fp.write(cmd)