blob: 87e6f81f2a761ad5ebbb180245ce68738d532d9e [file] [log] [blame]
Scott Bakerf93a06c2016-07-11 17:04:49 -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 module = AnsibleModule(
13 argument_spec = dict(
14 recipe = dict(required=True, type='str'),
15 username = dict(required=True, type='str'),
16 password = dict(required=True, type='str'),
17 hostname = dict(default="127.0.0.1", type="str"),
18 port = dict(default=80, type="int")
19 )
20 )
21
22 xos_auth=(module.params['username'], module.params['password'])
23
24 url = "http://%s:%d/api/utility/tosca/run/" % (module.params['hostname'], module.params['port'])
25
26 r = requests.post(url, data={"recipe": module.params['recipe']}, auth=xos_auth)
27 if (r.status_code != 200):
28 try:
29 error_text=r.json()["error_text"]
30 except:
31 error_text="error while formatting the error: " + traceback.format_exc()
32 module.fail_json(msg=error_text, rc=r.status_code)
33
34 result = r.json()
35 if "log_msgs" in result:
36 module.exit_json(changed=True, msg="\n".join(result["log_msgs"])+"\n")
37 else:
38 module.exit_json(changed=True, msg="success")
39
40if __name__ == '__main__':
41 main()