mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #8544 from Tenzer/faster-apt_repository
apt_repository: Check if key already exists before adding it
This commit is contained in:
commit
82564df61a
1 changed files with 7 additions and 2 deletions
|
@ -343,14 +343,19 @@ class UbuntuSourcesList(SourcesList):
|
||||||
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, distro.codename)
|
||||||
return line, ppa_owner, ppa_name
|
return line, ppa_owner, ppa_name
|
||||||
|
|
||||||
|
def _key_already_exists(self, key_fingerprint):
|
||||||
|
rc, out, err = self.module.run_command('apt-key export %s' % key_fingerprint, check_rc=True)
|
||||||
|
return len(err) == 0
|
||||||
|
|
||||||
def add_source(self, line, comment='', file=None):
|
def add_source(self, line, comment='', file=None):
|
||||||
if line.startswith('ppa:'):
|
if line.startswith('ppa:'):
|
||||||
source, ppa_owner, ppa_name = self._expand_ppa(line)
|
source, ppa_owner, ppa_name = self._expand_ppa(line)
|
||||||
|
|
||||||
if self.add_ppa_signing_keys_callback is not None:
|
if self.add_ppa_signing_keys_callback is not None:
|
||||||
info = self._get_ppa_info(ppa_owner, ppa_name)
|
info = self._get_ppa_info(ppa_owner, ppa_name)
|
||||||
command = ['apt-key', 'adv', '--recv-keys', '--keyserver', 'hkp://keyserver.ubuntu.com:80', info['signing_key_fingerprint']]
|
if not self._key_already_exists(info['signing_key_fingerprint']):
|
||||||
self.add_ppa_signing_keys_callback(command)
|
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, distro.codename))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue