mercredi 27 décembre 2017

Ansible uri call with Django JWT token

I would like to call django server with ansible:

I have called:

- name: Check status 200
    uri:
      url: https:///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:///api/users/auth/
    method: POST
    headers:
      Content-Type: "application/json"
      Authorization: "JWT "
    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?

Aucun commentaire:

Enregistrer un commentaire