(A) include errors in inventory scripts should they occur.

(B) allow registration with ignore_errors: True
pull/2712/head
Michael DeHaan 11 years ago
parent 6544af9616
commit d8bf87b008

@ -24,6 +24,7 @@ from ansible.inventory.host import Host
from ansible.inventory.group import Group
from ansible import utils
from ansible import errors
import sys
class InventoryScript(object):
''' Host inventory parser for ansible using external inventory scripts. '''
@ -41,9 +42,9 @@ class InventoryScript(object):
raise errors.AnsibleError("problem running %s (%s)" % (' '.join(cmd), e))
(stdout, stderr) = sp.communicate()
self.data = stdout
self.groups = self._parse()
self.groups = self._parse(stderr)
def _parse(self):
def _parse(self, err):
all_hosts = {}
self.raw = utils.parse_json(self.data)
@ -52,7 +53,8 @@ class InventoryScript(object):
group = None
if 'failed' in self.raw:
raise errors.AnsibleError("failed to parse executable inventory script results")
sys.stderr.write(err + "\n")
raise errors.AnsibleError("failed to parse executable inventory script results: %s" % self.raw)
for (group_name, data) in self.raw.items():

@ -350,6 +350,14 @@ class PlayBook(object):
result['stdout_lines'] = result['stdout'].splitlines()
self.SETUP_CACHE[host][task.register] = result
# also have to register some failed, but ignored, tasks
if task.ignore_errors and task.register:
failed = results.get('failed', {})
for host, result in failed.iteritems():
if 'stdout' in result:
result['stdout_lines'] = result['stdout'].splitlines()
self.SETUP_CACHE[host][task.register] = result
# flag which notify handlers need to be run
if len(task.notify) > 0:
for host, results in results.get('contacted',{}).iteritems():

Loading…
Cancel
Save