简体   繁体   中英

Installing PGP Key for Yum Repos Through Python API

I have looked at similar questions but no one mentions how I should approach this. I wanted to write a quick and dirty script that would help me bootstrap Puppet on fresh Fedora installs for some stuff I wanna try. From perusing the questions here. I had some sample code fixed up for my needs.

[root@srv ~]# python puppet-bootstrap.py 
[ 11/03/2012 02:16:47 PM ] begin bootstrap install for puppet client
[ 11/03/2012 02:16:47 PM ] package not found on system, installing
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 1aca3465: NOKEY
Public key for ruby-1.9.3.286-18.fc17.x86_64.rpm is not installed
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64
Importing GPG key 0x1ACA3465:
 Userid     : "Fedora (17) <fedora@fedoraproject.org>"
 Fingerprint: cac4 3fb7 74a4 a673 d81c 5de7 50e9 4c99 1aca 3465
 Package    : fedora-release-17-1.noarch (@fedora)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64
Traceback (most recent call last):
  File "puppet-bootstrap.py", line 17, in <module>
    yb.processTransaction()
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 6053, in processTransaction
    self._checkSignatures(pkgs,callback)
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 6096, in _checkSignatures
    self.getKeyForPackage(po, self._askForGPGKeyImport)
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 5798, in getKeyForPackage
    raise Errors.YumBaseError, _("Didn't install any keys")
yum.Errors.YumBaseError: Didn't install any keys

So how would I go about write a brief little code to accept the PGP key through the YUM Python API? The distro in question would be almost untouched, so the PGP key would have to be properly signed off in the case of this script. Anyone done this before?

Please add

yb.conf.assumeyes = True

Where appropriate. Egyou code should look like this:

#!/usr/bin/python
import yum

yb = yum.YumBase()
yb.conf.installroot = "/ipportvm/gittest/rootfs_testrootfs"
yb.conf.assumeyes = True
yb.conf.yumvar['releasever'] = '6'
for i in ("openssh-server", "plymouth", "rsyslog", "acpid", "ntp", "epel-release"):
    yb.install(name=i)
yb.resolveDeps()
yb.buildTransaction()
yb.processTransaction()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM