Issue
I would like to call django server with ansible:
I have called:
- name: Check status 200
uri:
url: https://{{ rest_server }}/api/users/api-token-auth/
method: POST
headers:
Content-Type: "application/json"
body: '{"username": "username", "password": "password"}'
return_content: yes
register: token
and I get the token. Now I would like to use this token for the next call, but I can't figure out how this is working....
I try
- name: Check that LOGIN returns a status 200
uri:
url: https://{{ rest_server }}/api/users/auth/
method: POST
headers:
Content-Type: "application/json"
Authorization: "JWT {{ token.content[token] }}"
body: '{"username": "user", "password": "pass"}'
return_content: yes
register: webpage
but I get error:
"msg": "The task includes an option with an undefined variable. The error was: ansible.utils.unsafe_proxy.AnsibleUnsafeText object has no element {u'cookies': {}, u'vary': u'Accept', u'access_control_allow_headers': u'Access-Control-Allow-Origin, Content-Type, X-CSRFToken, Authorization, Access-Bw, Content-Disposition', u'access_control_allow_methods': u'GET, DELETE, POST, PUT, OPTIONS', u'access_control_allow_credentials': u'true', u'content': u'{\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im1hcmtvLnphZHJhdmVjQHJlc3VsdC5zaSIsImV4cCI6MTUxNTAxNDE1OSwidXNlcl9pZCI6NCwidXNlcm5hbWUiOiJtYXJrby56YWRyYXZlY0ByZXN1bHQuc2kifQ.otlXbiuXnDJPiLrEKdMTKBgBMbvIGApBVH_aPI5mSd4\"}', 'failed': False, u'json': {u'token': u'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im1hcmtvLnphZHJhdmVjQHJlc3VsdC5zaSIsImV4cCI6MTUxNTAxNDE1OSwidXNlcl9pZCI6NCwidXNlcm5hbWUiOiJtYXJrby56YWRyYXZlY0ByZXN1bHQuc2kifQ.otlXbiuXnDJPiLrEKdMTKBgBMbvIGApBVH_aPI5mSd4'},....
What is the right way to do it?
Solution
uri
module returns content
as string.
Use {{ (token.content | from_json).token }}
or {{ token.json.token }}
.
Answered By - Konstantin Suvorov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.