Repository: ansible/ansible

Issue:
monit.py results in  ..."cmd": "/bin/monit summary -B", "failed"...
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ansible/lib/ansible/modules/monitoring/monit.py

##### ANSIBLE VERSION
```
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, May 29 2017, 20:42:36) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
```

##### CONFIGURATION
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30

##### OS / ENVIRONMENT
Red Hat Enterprise Linux Server release 7.4 (Maipo)

##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
task:
```
- monit:
    name: httpd
    state: reloaded
  become: true
```
Same results with other states

results in:
```
fatal: [myhost]: FAILED! => {"changed": false, "cmd": "/bin/monit summary -B", "failed": true, "msg": "Invalid option -- B  (-h will show valid options)", "rc": 1, "stderr": "Invalid option -- B  (-h will show valid options)\n", "stderr_lines": ["Invalid option -- B  (-h will show valid options)"], "stdout": "", "stdout_lines": []}
```

because this Monit version is installed:
```
/bin/monit -V
This is Monit version 5.14
Copyright (C) 2001-2015 Tildeslash Ltd. All Rights Reserved.
```

##### EXPECTED RESULTS
No errors

##### ACTUAL RESULTS
```
version_line="This is Monit version 5.14"
re.search("[0-9]+\.[0-9]+", version_line).group().split('.')
['5', '14']
MONIT_MAJOR_VERSION=5
MONIT_MINOR_VERSION=14
MONIT_MAJOR_VERSION > 3 or MONIT_MAJOR_VERSION == 3 and MONIT_MINOR_VERSION > 18
True
('summary', 'summary -B')[True]
'summary -B'
```
The end result should be:

```
'summary'
```




Discussion:
cc @brian-brazil @dstoflet
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/monitoring/monit.py b/lib/ansible/modules/monitoring/monit.py
--- a/lib/ansible/modules/monitoring/monit.py
+++ b/lib/ansible/modules/monitoring/monit.py
@@ -79,11 +79,11 @@ def monit_version():
         # Use only major and minor even if there are more these should be enough
         return int(version[0]), int(version[1])
 
-    def is_version_higher_than_18():
-        return MONIT_MAJOR_VERSION > 3 or MONIT_MAJOR_VERSION == 3 and MONIT_MINOR_VERSION > 18
+    def is_version_higher_than_5_18():
+        return (MONIT_MAJOR_VERSION, MONIT_MINOR_VERSION) > (5, 18)
 
     def parse(parts):
-        if is_version_higher_than_18():
+        if is_version_higher_than_5_18():
             return parse_current(parts)
         else:
             return parse_older_versions(parts)
@@ -138,7 +138,7 @@ def wait_for_monit_to_stop_pending():
 
     MONIT_MAJOR_VERSION, MONIT_MINOR_VERSION = monit_version()
 
-    SUMMARY_COMMAND = ('summary', 'summary -B')[is_version_higher_than_18()]
+    SUMMARY_COMMAND = ('summary', 'summary -B')[is_version_higher_than_5_18()]
 
     if state == 'reloaded':
         if module.check_mode:


Test patch: