blob: 14619feb5f15853fc12d88a972ce5dcadb85a18f [file] [log] [blame]
Zack Williamsa2763112017-01-03 11:38:38 -07001#!/usr/bin/python
2
3import json
4import os
5import requests
6import sys
7import traceback
8
9from ansible.module_utils.basic import AnsibleModule
10
11def main():
12
13 # args styled after the uri module
14 module = AnsibleModule(
15 argument_spec = dict(
16 url = dict(required=True, type='str'),
17 recipe = dict(required=True, type='str'),
18 user = dict(required=True, type='str'),
19 password = dict(required=True, type='str'),
20 )
21 )
22
23 xos_auth=(module.params['user'], module.params['password'])
24
25 r = requests.post(module.params['url'], data={"recipe": module.params['recipe']}, auth=xos_auth)
26 if (r.status_code != 200):
27 try:
28 error_text=r.json()["error_text"]
29 except:
30 error_text="error while formatting the error: " + traceback.format_exc()
31 module.fail_json(msg=error_text, rc=r.status_code)
32
33 result = r.json()
34 if "log_msgs" in result:
35 module.exit_json(changed=True, msg="\n".join(result["log_msgs"])+"\n")
36 else:
37 module.exit_json(changed=True, msg="success")
38
39if __name__ == '__main__':
40 main()