mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Added the 'test-module' script, useful for testing modules without running them in Ansible.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user