Hello,
While back I wrote some code just trying to learn how to interact with the REST API to do things like clean up groups/inventories, create inventories, etc.
To this I’d acquire a token then use that token in subsequent calls, for example:
t=requests.post(ANSIBLE_AUTH_URI, json={“username” : ANSIBLE_USER, “password”: ANSIBLE_PASS}, verify=False).json()
token=t[“token”]
j=requests.get(uris[“INVENTORIES_URI”], headers={“Authorization”: " Token " + token}, verify=False).json()
It has been a while since I looked at this code. Since I wrote it, I’ve upgraded the system I’m on, now using urllib3, Ansible Tower 3.4, so without prolonging the story… my code no longer works.
I’m having trouble with some of the basics, so for instance, my original code for authenticating no longer works.
If I try to call .json(), the program blows up pretty good complaining the data isn’t JSON.
If I remove the .json() call, and simply store the object returned like so:
t=requests.post(ANSIBLE_AUTH_URI, json={“username” : ANSIBLE_USER, “password”: ANSIBLE_PASS}, verify=False)
I don’t see how I can use ‘t’ to perform actions that require operations.
My questions:
How do I acquire a token?
Once I’ve got a token, how do I use it in subsequent calls so that I perform actions, for example, creating a group inside of an inventory?
Thank you,
Radesh