Skip to content

Commit

Permalink
apt_repository: Relax PPA checks and add basename (#5432)
Browse files Browse the repository at this point in the history
Allow installation of PPA repositories on non-Ubuntu Debian derived
distribution targets (e.g. neon, Mint, Debian itself) by removing the
specific check for UbuntuDistribution before allowing PPA: format
sources. This fixes the addition of PPA repositories under KDE neon (as
the codenames match the base Ubuntu distribution).

To make the functionality also useful under Mint and Debian which have
different codenames to their Ubuntu upstream / downstream releases, add
a 'codename' option to override the default used in the PPA source
entry.
  • Loading branch information
ribbons authored and mattclay committed Dec 8, 2016
1 parent be48ea4 commit df70a58
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/ansible/modules/packaging/os/apt_repository.py
Expand Up @@ -28,9 +28,8 @@
description:
- Add or remove an APT repositories in Ubuntu and Debian.
notes:
- This module works on Debian and Ubuntu.
- This module works on Debian, Ubuntu and their derivatives.
- This module supports Debian Squeeze (version 6) as well as its successors.
- This module treats Debian and Ubuntu distributions separately. So PPA could be installed only on Ubuntu machines.
options:
repo:
required: true
Expand Down Expand Up @@ -70,6 +69,12 @@
Defaults to a file name based on the repository source url.
The .list extension will be automatically added.
required: false
codename:
version_added: '2.3'
description:
- Override the distribution codename to use for PPA repositories.
Should usually only be set when working with a PPA on a non-Ubuntu target (e.g. Debian or Mint)
required: false
author: "Alexander Saltanov (@sashka)"
version_added: "0.7"
requirements:
Expand All @@ -90,9 +95,11 @@
# Remove specified repository from sources list.
apt_repository: repo='deb http://archive.canonical.com/ubuntu hardy partner' state=absent
# On Ubuntu target: add nginx stable repository from PPA and install its signing key.
# On Debian target: adding PPA is not available, so it will fail immediately.
# Add nginx stable repository from PPA and install its signing key.
# On Ubuntu target:
apt_repository: repo='ppa:nginx/stable'
# On Debian target
apt_repository: repo='ppa:nginx/stable' codename='trusty'
'''

import glob
Expand Down Expand Up @@ -375,6 +382,7 @@ class UbuntuSourcesList(SourcesList):
def __init__(self, module, add_ppa_signing_keys_callback=None):
self.module = module
self.add_ppa_signing_keys_callback = add_ppa_signing_keys_callback
self.codename = module.params['codename'] or distro.codename
super(UbuntuSourcesList, self).__init__(module)

def _get_ppa_info(self, owner_name, ppa_name):
Expand All @@ -394,7 +402,7 @@ def _expand_ppa(self, path):
except IndexError:
ppa_name = 'ppa'

line = 'deb http://ppa.launchpad.net/%s/%s/ubuntu %s main' % (ppa_owner, ppa_name, distro.codename)
line = 'deb http://ppa.launchpad.net/%s/%s/ubuntu %s main' % (ppa_owner, ppa_name, self.codename)
return line, ppa_owner, ppa_name

def _key_already_exists(self, key_fingerprint):
Expand All @@ -415,7 +423,7 @@ def add_source(self, line, comment='', file=None):
command = ['apt-key', 'adv', '--recv-keys', '--keyserver', 'hkp://keyserver.ubuntu.com:80', info['signing_key_fingerprint']]
self.add_ppa_signing_keys_callback(command)

file = file or self._suggest_filename('%s_%s' % (line, distro.codename))
file = file or self._suggest_filename('%s_%s' % (line, self.codename))
else:
source = self._parse(line, raise_if_invalid_or_disabled=True)[2]
file = file or self._suggest_filename(source)
Expand Down Expand Up @@ -469,6 +477,7 @@ def main():
# this should not be needed, but exists as a failsafe
install_python_apt=dict(required=False, default="yes", type='bool'),
validate_certs = dict(default='yes', type='bool'),
codename = dict(required=False),
),
supports_check_mode=True,
)
Expand All @@ -487,13 +496,11 @@ def main():
else:
module.fail_json(msg='%s is not installed, and install_python_apt is False' % PYTHON_APT)

if isinstance(distro, aptsources_distro.UbuntuDistribution):
if isinstance(distro, aptsources_distro.Distribution):
sourceslist = UbuntuSourcesList(module,
add_ppa_signing_keys_callback=get_add_ppa_signing_key_callback(module))
elif isinstance(distro, aptsources_distro.Distribution):
sourceslist = SourcesList(module)
else:
module.fail_json(msg='Module apt_repository supports only Debian and Ubuntu.')
module.fail_json(msg='Module apt_repository is not supported on target.')

sources_before = sourceslist.dump()

Expand Down

0 comments on commit df70a58

Please sign in to comment.