| 1 |
#!/usr/bin/python |
| 2 |
# I am an Ansible Python WANT_JSON module. I should receive a JSON-encoded file. |
| 3 |
|
| 4 |
import json |
| 5 |
import sys |
| 6 |
|
| 7 |
|
| 8 |
WANT_JSON = 1 |
| 9 |
|
| 10 |
|
| 11 |
def usage(): |
| 12 |
sys.stderr.write('Usage: %s <input.json>\n' % (sys.argv[0],)) |
| 13 |
sys.exit(1) |
| 14 |
|
| 15 |
if len(sys.argv) < 2: |
| 16 |
usage() |
| 17 |
|
| 18 |
# Also must slurp in our own source code, to verify the encoding string was |
| 19 |
# added. |
| 20 |
fp = open(sys.argv[0]) |
| 21 |
try: |
| 22 |
me = fp.read() |
| 23 |
finally: |
| 24 |
fp.close() |
| 25 |
|
| 26 |
try: |
| 27 |
fp = open(sys.argv[1]) |
| 28 |
try: |
| 29 |
input_json = fp.read() |
| 30 |
finally: |
| 31 |
fp.close() |
| 32 |
except IOError: |
| 33 |
usage() |
| 34 |
|
| 35 |
print("{") |
| 36 |
print(" \"changed\": false,") |
| 37 |
print(" \"msg\": \"Here is my input\",") |
| 38 |
print(" \"source\": [%s]," % (json.dumps(me),)) |
| 39 |
print(" \"input\": [%s]" % (input_json,)) |
| 40 |
print("}") |