mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Update uri.py (#56395)
1. Note that uri doesn't honor the no_proxy environment variable (due to https://github.com/ansible/ansible/issues/52705), and suggest a work around. 2. Added an example showing a test waiting for a URL to become available (using the `until:`, `retries:` and `delay:` settings) - based on https://gist.github.com/mikeifomin/67e233cd461331de16707ef59a07e372#gistcomment-2718587 Co-Authored-By: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
d56c975ce8
commit
77f3e8451c
1 changed files with 49 additions and 0 deletions
|
@ -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'''
|
||||
|
|
Loading…
Reference in a new issue