Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add checkmode support for test-module script

Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
  • Loading branch information...
commit b8cbf1370f3200ed478a3928f38e6840f3f5212a 1 parent 2769b3d
@hacosta hacosta authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 hacking/test-module
View
17 hacking/test-module
@@ -23,9 +23,10 @@
# modules
#
# example:
-# test-module -m ../library/command -a "/bin/sleep 3"
-# test-module -m ../library/service -a "name=httpd ensure=restarted"
-# test-module -m ../library/service -a "name=httpd ensure=restarted" --debugger /usr/bin/pdb
+# test-module -m ../library/commands/command -a "/bin/sleep 3"
+# test-module -m ../library/system/service -a "name=httpd ensure=restarted"
+# test-module -m ../library/system/service -a "name=httpd ensure=restarted" --debugger /usr/bin/pdb
+# test-modulr -m ../library/file/lineinfile -a "dest=/etc/exports line='/srv/home hostname1(rw,sync)'" --check
import sys
import base64
@@ -59,6 +60,8 @@ def parse():
parser.add_option('-I', '--interpreter', dest='interpreter',
help="path to interpeter to use for this module (e.g. ansible_python_interpreter=/usr/bin/python)",
metavar='INTERPRETER_TYPE=INTERPRETER_PATH')
+ parser.add_option('-c', '--check', dest='check', action='store_true',
+ help="run the module in check mode")
options, args = parser.parse_args()
if not options.module_path:
parser.print_help()
@@ -77,7 +80,7 @@ def write_argsfile(argstring, json=False):
argsfile.close()
return argspath
-def boilerplate_module(modfile, args, interpreter):
+def boilerplate_module(modfile, args, interpreter, check):
""" simulate what ansible does with new style modules """
#module_fh = open(modfile)
@@ -109,6 +112,10 @@ def boilerplate_module(modfile, args, interpreter):
if not interpreter_type.endswith('_interpreter'):
interpreter_type = '%s_interpreter' % interpreter_type
inject[interpreter_type] = interpreter_path
+
+ if check:
+ complex_args['CHECKMODE'] = True
+
(module_data, module_style, shebang) = replacer.modify_module(
modfile,
complex_args,
@@ -166,7 +173,7 @@ def rundebug(debugger, modfile, argspath):
def main():
options, args = parse()
- (modfile, module_style) = boilerplate_module(options.module_path, options.module_args, options.interpreter)
+ (modfile, module_style) = boilerplate_module(options.module_path, options.module_args, options.interpreter, options.check)
argspath=None
if module_style != 'new':
Please sign in to comment.
Something went wrong with that request. Please try again.