(A) include errors in inventory scripts should they occur.
(B) allow registration with ignore_errors: Truepull/4420/head
parent
6544af9616
commit
d8bf87b008
|
@ -24,6 +24,7 @@ from ansible.inventory.host import Host
|
||||||
from ansible.inventory.group import Group
|
from ansible.inventory.group import Group
|
||||||
from ansible import utils
|
from ansible import utils
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
|
import sys
|
||||||
|
|
||||||
class InventoryScript(object):
|
class InventoryScript(object):
|
||||||
''' Host inventory parser for ansible using external inventory scripts. '''
|
''' 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))
|
raise errors.AnsibleError("problem running %s (%s)" % (' '.join(cmd), e))
|
||||||
(stdout, stderr) = sp.communicate()
|
(stdout, stderr) = sp.communicate()
|
||||||
self.data = stdout
|
self.data = stdout
|
||||||
self.groups = self._parse()
|
self.groups = self._parse(stderr)
|
||||||
|
|
||||||
def _parse(self):
|
def _parse(self, err):
|
||||||
|
|
||||||
all_hosts = {}
|
all_hosts = {}
|
||||||
self.raw = utils.parse_json(self.data)
|
self.raw = utils.parse_json(self.data)
|
||||||
|
@ -52,7 +53,8 @@ class InventoryScript(object):
|
||||||
group = None
|
group = None
|
||||||
|
|
||||||
if 'failed' in self.raw:
|
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():
|
for (group_name, data) in self.raw.items():
|
||||||
|
|
||||||
|
|
|
@ -350,6 +350,14 @@ class PlayBook(object):
|
||||||
result['stdout_lines'] = result['stdout'].splitlines()
|
result['stdout_lines'] = result['stdout'].splitlines()
|
||||||
self.SETUP_CACHE[host][task.register] = result
|
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
|
# flag which notify handlers need to be run
|
||||||
if len(task.notify) > 0:
|
if len(task.notify) > 0:
|
||||||
for host, results in results.get('contacted',{}).iteritems():
|
for host, results in results.get('contacted',{}).iteritems():
|
||||||
|
|
Loading…
Reference in New Issue