mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-22 20:13:59 -07:00
win_get_url: Add use_proxy, headers and timeout (#26612)
* win_get_url: Add use_proxy, headers and timeout This PR includes: - Add use_proxy parameter - Add timeout parameter - Add headers parameter - Simplify logic - Create separate CheckModified-File - Now use -LiteralPath instead of -Path - Clean up documentation * win_get_url: Add use_proxy, headers and timeout This PR includes: - Add use_proxy parameter - Add timeout parameter - Add headers parameter - Simplify logic - Create separate CheckModified-File - Now use -LiteralPath instead of -Path - Clean up documentation
This commit is contained in:
parent
b84a48caef
commit
61d2201a2d
5 changed files with 296 additions and 199 deletions
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
|
||||
test_win_get_url_host: www.redhat.com
|
||||
test_win_get_url_link: "https://{{test_win_get_url_host}}"
|
||||
test_win_get_url_link: "https://{{ test_win_get_url_host }}"
|
||||
test_win_get_url_invalid_link: https://www.redhat.com/skynet_module.html
|
||||
test_win_get_url_invalid_path: 'Q:\Filez\Cyberdyne.html'
|
||||
test_win_get_url_invalid_path_dir: 'Q:\Filez\'
|
||||
test_win_get_url_path: '{{ test_win_get_url_dir_path }}\docs_index.html'
|
||||
test_win_get_url_path: '%TEMP%\docs_index.html'
|
||||
|
|
|
@ -16,120 +16,128 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- name: get tempdir path
|
||||
raw: $env:TEMP
|
||||
register: tempdir
|
||||
- setup:
|
||||
|
||||
- name: set output path dynamically
|
||||
set_fact:
|
||||
test_win_get_url_dir_path: "{{ tempdir.stdout_lines[0] }}"
|
||||
- name: Remove test file if it exists
|
||||
win_file:
|
||||
path: '{{ test_win_get_url_path }}'
|
||||
state: absent
|
||||
|
||||
- name: remove test file if it exists
|
||||
raw: >
|
||||
PowerShell -Command Remove-Item "{{test_win_get_url_path}}" -Force
|
||||
ignore_errors: true
|
||||
|
||||
- name: test win_get_url module
|
||||
- name: Test win_get_url module
|
||||
win_get_url:
|
||||
url: "{{test_win_get_url_link}}"
|
||||
dest: "{{test_win_get_url_path}}"
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: '{{ test_win_get_url_path }}'
|
||||
register: win_get_url_result
|
||||
|
||||
- name: check that url was downloaded
|
||||
- name: Check that url was downloaded
|
||||
assert:
|
||||
that:
|
||||
- "not win_get_url_result|failed"
|
||||
- "win_get_url_result|changed"
|
||||
- "win_get_url_result.win_get_url.url"
|
||||
- "win_get_url_result.win_get_url.dest"
|
||||
- not win_get_url_result|failed
|
||||
- win_get_url_result|changed
|
||||
- win_get_url_result.url
|
||||
- win_get_url_result.dest
|
||||
|
||||
- name: test win_get_url module again (force should be yes by default)
|
||||
- name: Test win_get_url module again (force should be yes by default)
|
||||
win_get_url:
|
||||
url: "{{test_win_get_url_link}}"
|
||||
dest: "{{test_win_get_url_path}}"
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: '{{ test_win_get_url_path }}'
|
||||
register: win_get_url_result_again
|
||||
|
||||
- name: check that url was downloaded again
|
||||
- name: Check that url was downloaded again
|
||||
assert:
|
||||
that:
|
||||
- "not win_get_url_result_again|failed"
|
||||
- "win_get_url_result_again|changed"
|
||||
- not win_get_url_result_again|failed
|
||||
- win_get_url_result_again|changed
|
||||
|
||||
- name: test win_get_url module again with force=no
|
||||
- name: Test win_get_url module again with force=no
|
||||
win_get_url:
|
||||
url: "{{test_win_get_url_link}}"
|
||||
dest: "{{test_win_get_url_path}}"
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: '{{ test_win_get_url_path }}'
|
||||
force: no
|
||||
register: win_get_url_result_noforce
|
||||
|
||||
- name: check that url was not downloaded again
|
||||
- name: Check that url was not downloaded again
|
||||
assert:
|
||||
that:
|
||||
- "not win_get_url_result_noforce|failed"
|
||||
- "not win_get_url_result_noforce|changed"
|
||||
- not win_get_url_result_noforce|failed
|
||||
- not win_get_url_result_noforce|changed
|
||||
|
||||
- name: test win_get_url module with url that returns a 404
|
||||
- name: Test win_get_url module with url that returns a 404
|
||||
win_get_url:
|
||||
url: "{{test_win_get_url_invalid_link}}"
|
||||
dest: "{{test_win_get_url_path}}"
|
||||
url: '{{ test_win_get_url_invalid_link }}'
|
||||
dest: '{{ test_win_get_url_path }}'
|
||||
register: win_get_url_result_invalid_link
|
||||
ignore_errors: true
|
||||
|
||||
- name: check that the download failed for an invalid url
|
||||
- name: Check that the download failed for an invalid url
|
||||
assert:
|
||||
that:
|
||||
- "win_get_url_result_invalid_link|failed"
|
||||
- win_get_url_result_invalid_link|failed
|
||||
- win_get_url_result_invalid_link.status_code == 404
|
||||
|
||||
- name: test win_get_url module with an invalid path
|
||||
- name: Test win_get_url module with an invalid path
|
||||
win_get_url:
|
||||
url: "{{test_win_get_url_link}}"
|
||||
dest: "{{test_win_get_url_invalid_path}}"
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: '{{ test_win_get_url_invalid_path }}'
|
||||
register: win_get_url_result_invalid_path
|
||||
ignore_errors: true
|
||||
|
||||
- name: check that the download failed for an invalid path
|
||||
- name: Check that the download failed for an invalid path
|
||||
assert:
|
||||
that:
|
||||
- "win_get_url_result_invalid_path|failed"
|
||||
- win_get_url_result_invalid_path|failed
|
||||
|
||||
- name: test win_get_url module with a valid path that is a directory
|
||||
- name: Test win_get_url module with a valid path that is a directory
|
||||
win_get_url:
|
||||
url: "{{test_win_get_url_link}}"
|
||||
dest: "{{test_win_get_url_dir_path}}"
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: '%TEMP%'
|
||||
register: win_get_url_result_dir_path
|
||||
ignore_errors: true
|
||||
|
||||
- name: check that the download did NOT fail, even though dest was directory
|
||||
- name: Check that the download did NOT fail, even though dest was directory
|
||||
assert:
|
||||
that:
|
||||
- "win_get_url_result_dir_path|changed"
|
||||
- win_get_url_result_dir_path|changed
|
||||
|
||||
- name: test win_get_url with a valid url path and a dest that is a directory (from 2.4 should use url path as filename)
|
||||
- name: Test win_get_url with a valid url path and a dest that is a directory (from 2.4 should use url path as filename)
|
||||
win_get_url:
|
||||
url: "{{test_win_get_url_link}}"
|
||||
dest: "{{test_win_get_url_dir_path}}"
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: '%TEMP%'
|
||||
register: win_get_url_result_dir_path_urlpath
|
||||
ignore_errors: true
|
||||
|
||||
- name: set expected destination path fact
|
||||
- name: Set expected destination path fact
|
||||
set_fact:
|
||||
expected_dest_path: '{{test_win_get_url_dir_path}}\{{test_win_get_url_host}}'
|
||||
expected_dest_path: '{{ ansible_env.TEMP }}\{{ test_win_get_url_host }}'
|
||||
|
||||
- name: check that the download succeeded (changed) and dest is as expected
|
||||
- name: Check that the download succeeded (changed) and dest is as expected
|
||||
assert:
|
||||
that:
|
||||
- "win_get_url_result_dir_path_urlpath|changed"
|
||||
- "win_get_url_result_dir_path_urlpath.win_get_url.actual_dest==expected_dest_path"
|
||||
- win_get_url_result_dir_path_urlpath|changed
|
||||
- win_get_url_result_dir_path_urlpath.dest == expected_dest_path
|
||||
|
||||
#- name: since 2.4 check you get a helpful message if the parent folder of the dest doesnt exist
|
||||
# win_get_url:
|
||||
# url: "{{test_win_get_url_link}}"
|
||||
# dest: "{{test_win_get_url_invalid_path_dir}}"
|
||||
# register: win_get_url_result_invalid_dest
|
||||
# ignore_errors: true
|
||||
#
|
||||
#- name: check if dest parent dir does not exist, module fails and you get a specific error message
|
||||
# assert:
|
||||
# that:
|
||||
# - "win_get_url_result_invalid_dest|failed"
|
||||
# - "win_get_url_result_invalid_dest.msg is search('does not exist')"
|
||||
- name: Check you get a helpful message if the parent folder of the dest doesn't exist
|
||||
win_get_url:
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: 'Q:\Filez\'
|
||||
register: win_get_url_result_invalid_dest
|
||||
ignore_errors: true
|
||||
|
||||
- name: Check if dest parent dir does not exist, module fails and you get a specific error message
|
||||
assert:
|
||||
that:
|
||||
- win_get_url_result_invalid_dest|failed
|
||||
- win_get_url_result_invalid_dest.msg is search('invalid path')
|
||||
|
||||
- name: Check you get a helpful message if the parent folder of the dest doesn't exist
|
||||
win_get_url:
|
||||
url: '{{ test_win_get_url_link }}'
|
||||
dest: 'C:\Filez\'
|
||||
register: win_get_url_result_invalid_dest2
|
||||
ignore_errors: true
|
||||
|
||||
- name: Check if dest parent dir does not exist, module fails and you get a specific error message
|
||||
assert:
|
||||
that:
|
||||
- win_get_url_result_invalid_dest2|failed
|
||||
- win_get_url_result_invalid_dest2.msg is search('does not exist')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue