From ee9619c5f737a0d8424e4e095172e24abd203980 Mon Sep 17 00:00:00 2001 From: Kavin Kankeshwar Date: Sun, 17 Feb 2013 23:15:27 -0800 Subject: [PATCH 1/2] teach apt module to support --check mode --- apt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apt b/apt index 3c8a270a6ce..ee91ee306c5 100644 --- a/apt +++ b/apt @@ -138,6 +138,9 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, install_reco if not install_recommends: cmd += " --no-install-recommends" + if m.check_mode: + m.exit_json(changed=True) + rc, out, err = m.run_command(cmd) if rc: m.fail_json(msg="'apt-get install %s' failed: %s" % (packages, err)) @@ -159,6 +162,10 @@ def remove(m, pkgspec, cache, purge=False): else: purge = '--purge' if purge else '' cmd = "%s -q -y %s remove %s" % (APT, purge,packages) + + if m.check_mode: + m.exit_json(changed=True) + rc, out, err = m.run_command(cmd) if rc: m.fail_json(msg="'apt-get remove %s' failed: %s" % (packages, err)) @@ -175,7 +182,8 @@ def main(): default_release = dict(default=None, aliases=['default-release']), install_recommends = dict(default='yes', aliases=['install-recommends'], choices=['yes', 'no']), force = dict(default='no', choices=['yes', 'no']) - ) + ), + supports_check_mode = True ) try: @@ -230,4 +238,3 @@ def main(): #<> main() - From fe9933ee475fb12d23d8babb0d5eeca60088dbd4 Mon Sep 17 00:00:00 2001 From: Kavin Kankeshwar Date: Sun, 17 Feb 2013 23:41:31 -0800 Subject: [PATCH 2/2] teach lineinfile module to support --check mode --- lineinfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lineinfile b/lineinfile index 9543450009c..89cc460095a 100644 --- a/lineinfile +++ b/lineinfile @@ -164,7 +164,7 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu msg = 'line added' changed = True - if changed: + if changed and not module.check_mode: if backup and os.path.exists(dest): module.backup_local(dest) f = open(dest, 'wb') @@ -189,7 +189,7 @@ def absent(module, dest, regexp, backup): lines = filter(matcher, lines) changed = len(found) > 0 - if changed: + if changed and not module.check_mode: if backup: module.backup_local(dest) f = open(dest, 'wb') @@ -209,7 +209,8 @@ def main(): create=dict(default=False, choices=BOOLEANS), backup=dict(default=False, choices=BOOLEANS), ), - mutually_exclusive = [['insertbefore', 'insertafter']] + mutually_exclusive = [['insertbefore', 'insertafter']], + supports_check_mode = True ) params = module.params