From cace2e72395211d7b6b33e041b1b3c798e78028d Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 14 Mar 2012 21:49:27 -0400 Subject: [PATCH] Added the 'test-module' script, useful for testing modules without running them in Ansible. --- service | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/service b/service index bb609a868de..d45da40867e 100755 --- a/service +++ b/service @@ -27,44 +27,26 @@ import shlex import subprocess # =========================================== -# convert arguments of form a=b c=d -# to a dictionary -# FIXME: make more idiomatic - - -if len(sys.argv) == 1: - print json.dumps({ - "failed" : True, - "msg" : "the command module requires arguments (-a)" - }) - sys.exit(1) argfile = sys.argv[1] -if not os.path.exists(argfile): - print json.dumps({ - "failed" : True, - "msg" : "Argument file not found" - }) - sys.exit(1) - args = open(argfile, 'r').read() -itmes = shlex.split(args) +items = shlex.split(args) if not len(items): - print json.dumps({ - "failed" : True, - "msg" : "the command module requires arguments (-a)" - }) + print "failed=True msg='the module requires arguments (-a)'" sys.exit(1) - params = {} for x in items: (k, v) = x.split("=") params[k] = v name = params['name'] -state = params.get('state','running') +state = params.get('state','unknown') + +if state not in [ 'running', 'stopped', 'restarted' ]: + print "failed=True msg='invalid state'" + sys.exit(1) # =========================================== # get service status