From 2dfc7122afa95832f2d4e4fffd038d9d5fbf0412 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 11 Jan 2015 04:27:10 +0100 Subject: [PATCH] Use the rpm python module rather than execing rpm Using the rpm module prevent a uneeded fork, and permit to skip the signature checking which slow down a bit the operation, and which would be done by yum on installation anyway. --- lib/ansible/modules/packaging/os/yum.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index bc4e598fa8d..db917720ae3 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -25,6 +25,7 @@ import traceback import os import yum +import rpm try: from yum.misc import find_unfinished_transactions, find_ts_remaining @@ -108,7 +109,7 @@ options: notes: [] # informational: requirements for nodes -requirements: [ yum, rpm ] +requirements: [ yum ] author: Seth Vidal ''' @@ -399,14 +400,19 @@ def transaction_exists(pkglist): def local_nvra(module, path): """return nvra of a local rpm passed in""" - - cmd = ['/bin/rpm', '-qp' ,'--qf', - '%{name}-%{version}-%{release}.%{arch}\n', path ] - rc, out, err = module.run_command(cmd) - if rc != 0: - return None - nvra = out.split('\n')[0] - return nvra + + ts = rpm.TransactionSet() + ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES) + fd = os.open(path, os.O_RDONLY) + try: + header = ts.hdrFromFdno(fd) + finally: + os.close(fd) + + return '%s-%s-%s.%s' % (header[rpm.RPMTAG_NAME], + header[rpm.RPMTAG_VERSION], + header[rpm.RPMTAG_RELEASE], + header[rpm.RPMTAG_ARCH]) def pkg_to_dict(pkgstr):