From 41619278e59c15f81cedbfdeef00e8c1c8e3746d Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Tue, 24 Apr 2012 11:03:14 -0400 Subject: [PATCH] handle issues when the hostlist is inadvertently set executable and/or executing it fails. This produces a nicer error message than a traceback --- lib/ansible/inventory.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/inventory.py b/lib/ansible/inventory.py index 18d64d60294..7cb8c7253eb 100644 --- a/lib/ansible/inventory.py +++ b/lib/ansible/inventory.py @@ -134,8 +134,12 @@ class Inventory(object): cmd = [self.inventory_file, '--list'] - cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) - out, err = cmd.communicate() + try: + cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) + out, err = cmd.communicate() + except Exception, e: + raise errors.AnsibleError("Failure executing %s to produce host list:\n %s" % (self.inventory_file, str(e))) + rc = cmd.returncode if rc: raise errors.AnsibleError("%s: %s" % self.inventory_file, err)