From e504ff94e6c8249eaf3f2f1299be775842ec73e0 Mon Sep 17 00:00:00 2001
From: abelbabel <kaltheat@gmail.com>
Date: Wed, 25 Sep 2013 17:51:17 +0200
Subject: [PATCH 1/3] add check mode support

Could it be that easy or do I have missed something?
---
 library/packaging/pkgng | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/library/packaging/pkgng b/library/packaging/pkgng
index fa341b2f80d..e6ad98e4b07 100644
--- a/library/packaging/pkgng
+++ b/library/packaging/pkgng
@@ -89,9 +89,10 @@ def remove_packages(module, pkgin_path, packages):
         if not query_package(module, pkgin_path, package):
             continue
 
-        rc, out, err = module.run_command("%s delete -y %s" % (pkgin_path, package))
+        if not module.check_mode:
+            rc, out, err = module.run_command("%s delete -y %s" % (pkgin_path, package))
 
-        if query_package(module, pkgin_path, package):
+        if not module.check_mode and query_package(module, pkgin_path, package):
             module.fail_json(msg="failed to remove %s: %s" % (package, out))
     
         remove_c += 1
@@ -110,7 +111,7 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
     if pkgsite != "":
         pkgsite="PACKAGESITE=%s" % (pkgsite)
 
-    if cached == "no":
+    if not module.check_mode and cached == "no":
         rc, out, err = module.run_command("%s %s update" % (pkgsite, pkgin_path))
         if rc != 0:
             module.fail_json(msg="Could not update catalogue")
@@ -119,9 +120,10 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
         if query_package(module, pkgin_path, package):
             continue
 
-        rc, out, err = module.run_command("%s %s install -U -y %s" % (pkgsite, pkgin_path, package))
+        if not module.check_mode:
+            rc, out, err = module.run_command("%s %s install -U -y %s" % (pkgsite, pkgin_path, package))
 
-        if not query_package(module, pkgin_path, package):
+        if not module.check_mode and query_package(module, pkgin_path, package):
             module.fail_json(msg="failed to install %s: %s" % (package, out))
 
         install_c += 1
@@ -134,11 +136,12 @@ def install_packages(module, pkgin_path, packages, cached, pkgsite):
 
 def main():
     module = AnsibleModule(
-            argument_spec    = dict(
-                state        = dict(default="present", choices=["present","absent"]),
-                name         = dict(aliases=["pkg"], required=True),
-                cached       = dict(default="no", required=False, choices=["yes","no"]),
-                pkgsite      = dict(default="", required=False)))
+            argument_spec       = dict(
+                state           = dict(default="present", choices=["present","absent"]),
+                name            = dict(aliases=["pkg"], required=True),
+                cached          = dict(default="supports_check_modeno", required=False, choices=["yes","no"]),
+                pkgsite         = dict(default="", required=False))
+            supports_check_mode = True)
 
     pkgin_path = module.get_bin_path('pkg', True)
 

From ee5ab48becd04b24852fdd840edec3906c45d68a Mon Sep 17 00:00:00 2001
From: abelbabel <kaltheat@gmail.com>
Date: Wed, 25 Sep 2013 18:38:46 +0200
Subject: [PATCH 2/3] removed typo

---
 library/packaging/pkgng | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/library/packaging/pkgng b/library/packaging/pkgng
index e6ad98e4b07..ea2c5262793 100644
--- a/library/packaging/pkgng
+++ b/library/packaging/pkgng
@@ -139,7 +139,7 @@ def main():
             argument_spec       = dict(
                 state           = dict(default="present", choices=["present","absent"]),
                 name            = dict(aliases=["pkg"], required=True),
-                cached          = dict(default="supports_check_modeno", required=False, choices=["yes","no"]),
+                cached          = dict(default="no", required=False, choices=["yes","no"]),
                 pkgsite         = dict(default="", required=False))
             supports_check_mode = True)
 

From effcb963f63ca21ee2908ac4cfa5d92b72915cd2 Mon Sep 17 00:00:00 2001
From: abelbabel <kaltheat@gmail.com>
Date: Wed, 25 Sep 2013 18:50:41 +0200
Subject: [PATCH 3/3] typo

---
 library/packaging/pkgng | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/library/packaging/pkgng b/library/packaging/pkgng
index ea2c5262793..af1fdf93ef1 100644
--- a/library/packaging/pkgng
+++ b/library/packaging/pkgng
@@ -140,7 +140,7 @@ def main():
                 state           = dict(default="present", choices=["present","absent"]),
                 name            = dict(aliases=["pkg"], required=True),
                 cached          = dict(default="no", required=False, choices=["yes","no"]),
-                pkgsite         = dict(default="", required=False))
+                pkgsite         = dict(default="", required=False)),
             supports_check_mode = True)
 
     pkgin_path = module.get_bin_path('pkg', True)