From 2592b2c3f9c8021cab4d563125ab905c1484353d Mon Sep 17 00:00:00 2001
From: Maykel Moya <mmoya@speedyrails.com>
Date: Thu, 17 Oct 2013 11:59:12 +0200
Subject: [PATCH] Do key validation only when key is provided

key_id is optional, the previous code didn't handle the case of key_id
not specified
---
 library/packaging/apt_key | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/library/packaging/apt_key b/library/packaging/apt_key
index c9a85313b2..48c3873eb3 100644
--- a/library/packaging/apt_key
+++ b/library/packaging/apt_key
@@ -188,11 +188,12 @@ def main():
     state           = module.params['state']
     changed         = False
 
-    try:
-        _ = int(key_id, 16)
-        key_id = key_id.lstrip('0x')
-    except ValueError:
-        module.fail_json("Invalid key_id")
+    if key_id:
+        try:
+            _ = int(key_id, 16)
+            key_id = key_id.lstrip('0x')
+        except ValueError:
+            module.fail_json("Invalid key_id")
 
     # FIXME: I think we have a common facility for this, if not, want
     check_missing_binaries(module)