Ansible URI module throwing Connection timed out exception

Solution In Progress - Updated -

Environment

  • Ansible Automation Platform 2.x

Issue

  • While connecting API endpoint via ansible.builtin.uri URI module gives the status code of "-1 but through Curl or python it returns the valid result.

    - name: connect to service now cmdb table
      ansible.builtin.uri:
        url: https://<servicenow-url>/api/now/table/cmdb_ci_linux_server
        method: GET
        body_format: form-urlencoded
        body:
        name: "{{cmdb_user}}"
        password: "{{cmdb_password}}"
        enter: Sign in
        timeout: 2000
        validate_certs: no
      register: content
    
  • Running the ansible play throws the following error:

    fatal: [localhost]: FAILED! => {"changed": false, "content": "", "elapsed": 129, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno 110] Connection timed out>", "redirected": false, "status": -1, "url": "https://<servicenowurl>/api/now/table/cmdb_ci_linux_server"}
    

Resolution

  • Need to correct the connectivity issue between ansible controller and API endpoint to avoid above exception.

Root Cause

  • There is connectivity issue between Ansible controller and API endpoint due to which URI module fails with "-1" status code exception.

Diagnostic Steps

  • Need to verify below points to ensure if it is a Networking issue:

    • Is there any firewall between Ansible and the endpoint?
    • Does the proxy blocking the connectivity between source and target endpoints?
    • Is the playbook ran with host set to localhost and contain "use_proxy: no" as an extra environment variable?
  • If use_proxy is set to false at the playbook code, it will not use a proxy, even if one is defined in an environment variable on the target hosts. Hence, it's given more precedence. Please check the reference for the same.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments