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)