ansibleuriansible-tower

Ansible uri module "urlopen error [Errno -2] Name or service not known"


I would like to make API request to internet using Ansible Tower and a playbook but I have an error. In this example, I try to request https://www.google.com, but the result is the same with others websites. Here you can see my playbook :

---
- name: API call
  environment:
    http_proxy: 'http://{{ username_proxy }}:{{ password_proxy }}@{{ url_proxy }}:8080'
    https_proxy: 'http://{{ username_proxy }}:{{ password_proxy }}@{{ url_proxy }}:8080'
    
  block:
    - name: "Launch API call"
      uri:
        url: "https://www.google.com/"
        return_content: yes
        method: GET
        validate_certs: no
      register: webpage
    
    - name: debug
      debug:
        var: webpage.content    

Here you can see the result with the error msg :

{
    "status": -1,
    "_ansible_no_log": false,
    "url": "https://www.google.com/",
    "changed": false,
    "elapsed": 0,
    "content": "",
    "invocation": {
        "module_args": {
            "directory_mode": null,
            "force": false,
            "remote_src": null,
            "status_code": [
                200
            ],
            "follow": false,
            "owner": null,
            "body_format": "raw",
            "client_key": null,
            "group": null,
            "use_proxy": true,
            "unix_socket": null,
            "unsafe_writes": null,
            "serole": null,
            "content": null,
            "setype": null,
            "follow_redirects": "safe",
            "return_content": true,
            "method": "GET",
            "body": null,
            "url_username": null,
            "url_password": null,
            "dest": null,
            "selevel": null,
            "force_basic_auth": false,
            "removes": null,
            "http_agent": "ansible-httpget",
            "regexp": null,
            "src": null,
            "url": "https://www.google.com/",
            "backup": null,
            "seuser": null,
            "client_cert": null,
            "creates": null,
            "headers": {},
            "delimiter": null,
            "mode": null,
            "timeout": 30,
            "attributes": null,
            "validate_certs": false
        }
    },
    "redirected": false,
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno -2] Name or service not known>"
}

Do you have any idea of the origin of the error please ?

Thank you for your time.


Solution

  • I want to close my question, I wrote the port in the variable {{ url_proxy }} and also after it, it was a doublon.