From 5d63d0b8d124b87488d47bbd0503178a25cba8fd Mon Sep 17 00:00:00 2001
From: Strahinja Kustudic <kustodian@gmail.com>
Date: Thu, 16 Jun 2016 18:46:12 +0200
Subject: [PATCH] Fixes check mode error on Python 2.4 and wrong changed state
 (#2438)

* Fixes check mode error on Python 2.4 and wrong changed state

* Changes code as suggested by @bcoca
---
 .../database/postgresql/postgresql_ext.py     | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py b/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py
index 7a259d07c7..73125d5cca 100644
--- a/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py
+++ b/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py
@@ -164,23 +164,22 @@ def main():
 
     try:
         if module.check_mode:
-            if state == "absent":
+            if state == "present":
                 changed = not ext_exists(cursor, ext)
-            elif state == "present":
+            elif state == "absent":
                 changed = ext_exists(cursor, ext)
-            module.exit_json(changed=changed,ext=ext)
-
-        if state == "absent":
-            changed = ext_delete(cursor, ext)
-
-        elif state == "present":
-            changed = ext_create(cursor, ext)
+        else:
+            if state == "absent":
+                changed = ext_delete(cursor, ext)
+    
+            elif state == "present":
+                changed = ext_create(cursor, ext)
     except NotSupportedError, e:
         module.fail_json(msg=str(e))
     except Exception, e:
         module.fail_json(msg="Database query failed: %s" % e)
 
-    module.exit_json(changed=changed, db=db)
+    module.exit_json(changed=changed, db=db, ext=ext)
 
 # import module snippets
 from ansible.module_utils.basic import *