diff --git a/changelogs/fragments/ppa_https.yml b/changelogs/fragments/ppa_https.yml new file mode 100644 index 00000000000..7f6d95a6d3a --- /dev/null +++ b/changelogs/fragments/ppa_https.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - apt_repository - update PPA URL to point to https URL (https://github.com/ansible/ansible/issues/82463). diff --git a/lib/ansible/modules/apt_repository.py b/lib/ansible/modules/apt_repository.py index bea93340c6f..5cb4b14308e 100644 --- a/lib/ansible/modules/apt_repository.py +++ b/lib/ansible/modules/apt_repository.py @@ -465,6 +465,7 @@ class UbuntuSourcesList(SourcesList): # prefer api.launchpad.net over launchpad.net/api # see: https://github.com/ansible/ansible/pull/81978#issuecomment-1767062178 LP_API = 'https://api.launchpad.net/1.0/~%s/+archive/%s' + PPA_URI = 'https://ppa.launchpadcontent.net' def __init__(self, module): self.module = module @@ -496,7 +497,7 @@ class UbuntuSourcesList(SourcesList): except IndexError: ppa_name = 'ppa' - line = 'deb http://ppa.launchpad.net/%s/%s/ubuntu %s main' % (ppa_owner, ppa_name, self.codename) + line = 'deb %s/%s/%s/ubuntu %s main' % (self.PPA_URI, ppa_owner, ppa_name, self.codename) return line, ppa_owner, ppa_name def _key_already_exists(self, key_fingerprint): diff --git a/test/integration/targets/apt_repository/tasks/apt.yml b/test/integration/targets/apt_repository/tasks/apt.yml index 04e9ce5d60c..6c05e00dd72 100644 --- a/test/integration/targets/apt_repository/tasks/apt.yml +++ b/test/integration/targets/apt_repository/tasks/apt.yml @@ -3,7 +3,7 @@ - set_fact: test_ppa_name: 'ppa:git-core/ppa' test_ppa_filename: 'git-core' - test_ppa_spec: 'deb http://ppa.launchpad.net/git-core/ppa/ubuntu {{ansible_distribution_release}} main' + test_ppa_spec: 'deb https://ppa.launchpadcontent.net/git-core/ppa/ubuntu {{ansible_distribution_release}} main' test_ppa_key: 'E1DF1F24' # http://keyserver.ubuntu.com:11371/pks/lookup?search=0xD06AAF4C11DAB86DF421421EFE6B20ECA7AD98A1&op=index - name: show python version @@ -288,6 +288,47 @@ apt: pkg=local-apt-repository state=absent purge=yes # +# TEST: PPA HTTPS URL +# +- name: Add PPA using HTTPS URL + apt_repository: + repo: 'ppa:deadsnakes' + filename: 'deadsnakes' + state: present + register: result + +- name: Check if PPA using HTTPS URL is added + assert: + that: + - 'result.changed' + - 'result.state == "present"' + - 'result.repo == "ppa:deadsnakes"' + +- name: 'examine source file' + stat: + path: '/etc/apt/sources.list.d/deadsnakes.list' + register: source_file + +- name: 'assert source file exists' + assert: + that: + - 'source_file.stat.exists == True' + +- name: Check if the PPA URL + shell: "grep 'https://ppa.launchpadcontent.net' /etc/apt/sources.list.d/deadsnakes.list" + register: r + +- name: Test if PPA URL points to https URL + assert: + that: + - r.changed + - "'https://ppa.launchpadcontent.net' in r.stdout" + +- name: Remove PPA file + file: + path: '/etc/apt/sources.list.d/deadsnakes.list' + state: absent +# # TEARDOWN # - import_tasks: 'cleanup.yml'