Skip to content

Commit

Permalink
[bp/2.15] deb822_repository: use http-agent with open_url
Browse files Browse the repository at this point in the history
* Use http-agent in open_url API while getting
  cloudflare content

Fixes: #80809

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed May 25, 2023
1 parent 94b97c9 commit f01c724
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/deb822_open_url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- deb822_repository - use http-agent for receiving content (https://github.com/ansible/ansible/issues/80809).
1 change: 1 addition & 0 deletions lib/ansible/module_utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,3 +2068,4 @@ def fetch_file(module, url, data=None, headers=None, method=None,
except Exception as e:
module.fail_json(msg="Failure downloading %s, %s" % (url, to_native(e)))
return fetch_temp_file.name

2 changes: 1 addition & 1 deletion lib/ansible/modules/deb822_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def write_signed_by_key(module, v, slug):
parts = generic_urlparse(urlparse(v))
if parts.scheme:
try:
r = open_url(v)
r = open_url(v, http_agent='ansible-httpget')
except Exception as exc:
raise_from(RuntimeError(to_native(exc)), exc)
else:
Expand Down
18 changes: 17 additions & 1 deletion test/integration/targets/deb822_repository/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- main
- restricted
register: deb822_check_mode_1
check_mode: yes
check_mode: true

- name: Create deb822 repo
deb822_repository:
Expand Down Expand Up @@ -211,3 +211,19 @@
that:
- ansible_test_repo_remove is changed
- ansible_test_repo_stats.results|map(attribute='stat')|selectattr('exists') == []

- name: Check if http-agent works when using cloudflare repo - check_mode
deb822_repository:
name: cloudflared
types: deb
uris: https://pkg.cloudflare.com/cloudflared
suites: "bullseye"
components: main
signed_by: https://pkg.cloudflare.com/cloudflare-main.gpg
state: present
check_mode: true
register: ansible_test_http_agent

- assert:
that:
- ansible_test_http_agent is changed

0 comments on commit f01c724

Please sign in to comment.