From c9e62d7061d6b00d85d9e0726eb443c18278f3b7 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 7 Nov 2012 15:16:00 +0100 Subject: [PATCH] Fix for an exception when for whatever reason the inventory script fails This avoids a traceback that gave no clue as to what was happening. This is in line with the change from #1535 --- lib/ansible/inventory/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 865a6acf8d..3c679ba67e 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -279,12 +279,12 @@ class Inventory(object): vars.update(updated) if self._is_script: - cmd = subprocess.Popen( - [self.host_list,"--host",hostname], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE - ) - (out, err) = cmd.communicate() + cmd = [self.host_list,"--host",hostname] + try: + sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + except OSError, e: + raise errors.AnsibleError("problem running %s (%s)" % (' '.join(cmd), e)) + (out, err) = sp.communicate() results = utils.parse_json(out) # FIXME: this is a bit redundant with host.py and should share code