diff --git a/examples/playbook/modules/bin_bash_module.sh b/examples/playbook/modules/bin_bash_module.sh new file mode 100755 index 00000000..01abff0c --- /dev/null +++ b/examples/playbook/modules/bin_bash_module.sh @@ -0,0 +1,5 @@ +#!/bin/bash +exec >/tmp/derp +echo "$1" +cat "$1" + diff --git a/examples/playbook/modules/json_args_python.py b/examples/playbook/modules/json_args_python.py new file mode 100644 index 00000000..45689584 --- /dev/null +++ b/examples/playbook/modules/json_args_python.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +# I am an Ansible Python JSONARGS module. I should receive an encoding string. + +import json +import sys + +json_arguments = """<>""" + +print "{" +print " \"changed\": false," +print " \"msg\": \"Here is my input\"," +print " \"input\": [%s]" % (json_arguments,) +print "}" diff --git a/examples/playbook/modules/old_style_module.sh b/examples/playbook/modules/old_style_module.sh new file mode 100755 index 00000000..47e6afbd --- /dev/null +++ b/examples/playbook/modules/old_style_module.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# I am an Ansible old-style module. + +INPUT=$1 + +[ ! -r "$INPUT" ] && { + echo "Usage: $0 " >&2 + exit 1 +} + +echo "{" +echo " \"changed\": false," +echo " \"msg\": \"Here is my input\"," +echo " \"filname\": \"$INPUT\"," +echo " \"input\": [\"$(cat $INPUT | tr \" \' )\"]" +echo "}" diff --git a/examples/playbook/modules/python_new_style_module.py b/examples/playbook/modules/python_new_style_module.py new file mode 100755 index 00000000..06d031b1 --- /dev/null +++ b/examples/playbook/modules/python_new_style_module.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +# I am an Ansible new-style Python module. I should receive an encoding string. + +import json +import sys + +# This is the magic marker Ansible looks for: +# from ansible.module_utils. + + +def usage(): + sys.stderr.write('Usage: %s \n' % (sys.argv[0],)) + sys.exit(1) + +# Also must slurp in our own source code, to verify the encoding string was +# added. +print 'WTFFFFFFFFFFFFFFFF %r' % (sys.argv,) +with open(sys.argv[0]) as fp: + me = fp.read() + +input_json = sys.stdin.read() + +print "{" +print " \"changed\": false," +print " \"msg\": \"Here is my input\"," +print " \"source\": [%s]," % (json.dumps(me),) +print " \"input\": [%s]" % (input_json,) +print "}" diff --git a/examples/playbook/modules/python_want_json_module.py b/examples/playbook/modules/python_want_json_module.py new file mode 100755 index 00000000..bd12704e --- /dev/null +++ b/examples/playbook/modules/python_want_json_module.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +# I am an Ansible Python WANT_JSON module. I should receive an encoding string. + +import json +import sys + +WANT_JSON = 1 + + +def usage(): + sys.stderr.write('Usage: %s \n' % (sys.argv[0],)) + sys.exit(1) + +if len(sys.argv) < 2: + usage() + +# Also must slurp in our own source code, to verify the encoding string was +# added. +with open(sys.argv[0]) as fp: + me = fp.read() + +try: + with open(sys.argv[1]) as fp: + input_json = fp.read() +except IOError: + usage() + +print "{" +print " \"changed\": false," +print " \"msg\": \"Here is my input\"," +print " \"source\": [%s]," % (json.dumps(me),) +print " \"input\": [%s]" % (input_json,) +print "}" diff --git a/examples/playbook/modules/want_json_module.sh b/examples/playbook/modules/want_json_module.sh new file mode 100755 index 00000000..6053eacd --- /dev/null +++ b/examples/playbook/modules/want_json_module.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# I am an Ansible WANT_JSON module. + +WANT_JSON=1 +INPUT=$1 + +[ ! -r "$INPUT" ] && { + echo "Usage: $0 " >&2 + exit 1 +} + +echo "{" +echo " \"changed\": false," +echo " \"msg\": \"Here is my input\"," +echo " \"input\": [$(< $INPUT)]" +echo "}"