ansible profile
Change-Id: I6c577b6852b4b53812c4ddca6dc83b042caefe30
diff --git a/cord-pod-ansible/library/xostosca.py b/cord-pod-ansible/library/xostosca.py
new file mode 100644
index 0000000..87e6f81
--- /dev/null
+++ b/cord-pod-ansible/library/xostosca.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+
+import json
+import os
+import requests
+import sys
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+
+def main():
+ module = AnsibleModule(
+ argument_spec = dict(
+ recipe = dict(required=True, type='str'),
+ username = dict(required=True, type='str'),
+ password = dict(required=True, type='str'),
+ hostname = dict(default="127.0.0.1", type="str"),
+ port = dict(default=80, type="int")
+ )
+ )
+
+ xos_auth=(module.params['username'], module.params['password'])
+
+ url = "http://%s:%d/api/utility/tosca/run/" % (module.params['hostname'], module.params['port'])
+
+ r = requests.post(url, data={"recipe": module.params['recipe']}, auth=xos_auth)
+ if (r.status_code != 200):
+ try:
+ error_text=r.json()["error_text"]
+ except:
+ error_text="error while formatting the error: " + traceback.format_exc()
+ module.fail_json(msg=error_text, rc=r.status_code)
+
+ result = r.json()
+ if "log_msgs" in result:
+ module.exit_json(changed=True, msg="\n".join(result["log_msgs"])+"\n")
+ else:
+ module.exit_json(changed=True, msg="success")
+
+if __name__ == '__main__':
+ main()