--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/907ddbd3-4b57-4f15-8005-7828b7e873c4n%40googlegroups.com.
Hi Rahul,
Now I understand the context. Not sure if the HTTP Basic Auth library is the best method to authenticate. Anyway, I left an example that uses password method (more here).
import requests # host definition rdeck_instance = "localhost" rdeck_port = "4440" rdeck_api = "44" rdeck_username = "admin" rdeck_password = "admin" rdeck_job_id = "279fe1b1-07b7-4272-9512-6eae512bb9a1" # connect to instance s = requests.Session() r = s.post("http://" + rdeck_instance + ":" + rdeck_port +"/j_security_check", data={"j_username": rdeck_username, "j_password": rdeck_password}) r.status_code r.url # print data (for debug) print ('######################') print (r.status_code) print (r.url) print ('######################') r = s.post("http://" + rdeck_instance + ":" + rdeck_port +"/api/" + rdeck_api + "/job/" + rdeck_job_id + "/run",headers = {'Accept': 'application/json'}) # json response print(r.json())Tested on Rundeck 4.15.
Feel free to modify it if you like. I’m not a python expert but this works :-)
Hope it helps!
Here the version “with options”
import requests # host definition rdeck_instance = "localhost" rdeck_port = "4440" rdeck_api = "44" rdeck_username = "admin" rdeck_password = "admin" rdeck_job_id = "279fe1b1-07b7-4272-9512-6eae512bb9a1" rdeck_option_name = "opt1" rdeck_option_value = "world!!" # connect to instance s = requests.Session() r = s.post("http://" + rdeck_instance + ":" + rdeck_port +"/j_security_check", data={ "j_username": rdeck_username, "j_password": rdeck_password }) r.status_code r.url # print data (for debug) print ('######################') print (r.status_code) print (r.url) print ('######################') r = s.post("http://" + rdeck_instance + ":" + rdeck_port +"/api/" + rdeck_api + "/job/" + rdeck_job_id + "/run", data={ "argString": "-%s %s" %(rdeck_option_name, rdeck_option_value) }, headers = {'Accept': 'application/json'}) # json response print(r.json())Also tested on Rundeck 4.15.
Regards.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/6e850480-f7d2-45ce-913e-76f8be3325d1n%40googlegroups.com.