I have a playbook which looks like

- name: CURL post example
    url: "https://dev-box.local/api/"
    method: POST
    body: '{
           "max_conns": 0,
           "max_fails": 2,
           "fail_timeout": "3s"
    body_format: json
    validate_certs: no
    return_content: yes
    force_basic_auth: yes
      Content-Type: "application/json"

but during the execution I'm getting

 FAILED! => {"changed": false, "connection": "close", "content": "{\"status\":403,\"message\":\"Forbidden\"}\n", "content_length": "37", "content_type": "application/json", "date": "Thu, 03 Dec 2020 21:03:13 GMT", "elapsed": 0, "json": {"message": "Forbidden", "status": 403}, "msg": "Status code was 403 and not [200]: HTTP Error 403: Forbidden", 

when I will do the same call as the curl -k from the command line on the same box as ansible it works fine.

Any thoughts on that?

1 Answer 1


You seem to be passing force_basic_auth: yes but no user, nor password.

Example from the Ansible docs:

- name: Create a JIRA issue
    url: https://your.jira.example.com/rest/api/2/issue/
    method: POST
    user: your_username
    password: your_pass
    body: "{{ lookup('file','issue.json') }}"
    force_basic_auth: yes
    status_code: 201
    body_format: json

The 403 is usually Basic Auth failing. If it's not, it could be the API server you're running requiring some sort of authentication.

If the curl -k command includes something like https://user:[email protected]/api/ or the --user <user:password>, it should work. Or maybe it's using data from .netrc?

I hope this helps.

  • yeah - that + adding become: true fixed that Dec 4, 2020 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.