From 6bddb3d3c1526fe79cdbc0687f77749f20f58e37 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 7 Jun 2023 07:16:27 -0700 Subject: [PATCH] [bp/2.15] deb822_repository: use http-agent with open_url (#80894) * Use http-agent in open_url API while getting cloudflare content Fixes: #80809 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/deb822_open_url.yml | 2 ++ lib/ansible/modules/deb822_repository.py | 2 +- .../targets/deb822_repository/tasks/test.yml | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/deb822_open_url.yml diff --git a/changelogs/fragments/deb822_open_url.yml b/changelogs/fragments/deb822_open_url.yml new file mode 100644 index 00000000000..222268aad26 --- /dev/null +++ b/changelogs/fragments/deb822_open_url.yml @@ -0,0 +1,2 @@ +bugfixes: +- deb822_repository - use http-agent for receiving content (https://github.com/ansible/ansible/issues/80809). diff --git a/lib/ansible/modules/deb822_repository.py b/lib/ansible/modules/deb822_repository.py index 0c706ce06ec..9f90b88e06a 100644 --- a/lib/ansible/modules/deb822_repository.py +++ b/lib/ansible/modules/deb822_repository.py @@ -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: diff --git a/test/integration/targets/deb822_repository/tasks/test.yml b/test/integration/targets/deb822_repository/tasks/test.yml index 3231cbeb95a..4911bb92a5e 100644 --- a/test/integration/targets/deb822_repository/tasks/test.yml +++ b/test/integration/targets/deb822_repository/tasks/test.yml @@ -9,7 +9,7 @@ - main - restricted register: deb822_check_mode_1 - check_mode: yes + check_mode: true - name: Create deb822 repo deb822_repository: @@ -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