diff --git a/lib/ansible/modules/net_tools/basics/uri.py b/lib/ansible/modules/net_tools/basics/uri.py index 455d7729c92..f1c0c747b63 100644 --- a/lib/ansible/modules/net_tools/basics/uri.py +++ b/lib/ansible/modules/net_tools/basics/uri.py @@ -259,6 +259,55 @@ EXAMPLES = r''' method: POST src: /path/to/my/file.json remote_src: yes + +- name: Pause play until a URL is reachable from this host + uri: + url: "http://192.0.2.1/some/test" + follow_redirects: none + method: GET + register: _result + until: _result.status == 200 + retries: 720 # 720 * 5 seconds = 1hour (60*60/5) + delay: 5 # Every 5 seconds + +# There are issues in a supporting Python library that is discussed in +# https://github.com/ansible/ansible/issues/52705 where a proxy is defined +# but you want to bypass proxy use on CIDR masks by using no_proxy +- name: Work around a python issue that doesn't support no_proxy envvar + uri: + follow_redirects: none + validate_certs: false + timeout: 5 + url: "http://{{ ip_address }}:{{ port | default(80) }}" + register: uri_data + failed_when: false + changed_when: false + vars: + ip_address: 192.0.2.1 + environment: | + { + {% for no_proxy in (lookup('env', 'no_proxy') | regex_replace('\s*,\s*', ' ') ).split() %} + {% if no_proxy | regex_search('\/') and + no_proxy | ipaddr('net') != '' and + no_proxy | ipaddr('net') != false and + ip_address | ipaddr(no_proxy) is not none and + ip_address | ipaddr(no_proxy) != false %} + 'no_proxy': '{{ ip_address }}' + {% elif no_proxy | regex_search(':') != '' and + no_proxy | regex_search(':') != false and + no_proxy == ip_address + ':' + (port | default(80)) %} + 'no_proxy': '{{ ip_address }}:{{ port | default(80) }}' + {% elif no_proxy | ipaddr('host') != '' and + no_proxy | ipaddr('host') != false and + no_proxy == ip_address %} + 'no_proxy': '{{ ip_address }}' + {% elif no_proxy | regex_search('^(\*|)\.') != '' and + no_proxy | regex_search('^(\*|)\.') != false and + no_proxy | regex_replace('\*', '') in ip_address %} + 'no_proxy': '{{ ip_address }}' + {% endif %} + {% endfor %} + } ''' RETURN = r'''