1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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

(B) allow registration with ignore_errors: True
This commit is contained in:
Michael DeHaan 2013-04-17 22:27:00 -04:00
parent 6544af9616
commit d8bf87b008
2 changed files with 13 additions and 3 deletions

View file

@ -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():

View file

@ -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():