From f1261343f4785635ff034ad5fc79cbb915530dce Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Wed, 23 Jul 2014 19:22:49 -0500 Subject: [PATCH] clean up and add some minor logging make --roster-file work with the ansible roster --- salt/roster/__init__.py | 8 +++++++- salt/roster/ansible.py | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/salt/roster/__init__.py b/salt/roster/__init__.py index add0c9b21e..051949321b 100644 --- a/salt/roster/__init__.py +++ b/salt/roster/__init__.py @@ -9,6 +9,9 @@ systems that cannot or should not host a minion agent. # Import salt libs import salt.loader +import logging +log = logging.getLogger(__name__) + class Roster(object): ''' @@ -45,5 +48,8 @@ class Roster(object): f_str = '{0}.targets'.format(back) if f_str not in self.rosters: continue - targets.update(self.rosters[f_str](tgt, tgt_type)) + try: + targets.update(self.rosters[f_str](tgt, tgt_type)) + except salt.exceptions.SaltRenderError as exc: + log.debug('Unable to render roster file: {0}'.format(exc.error)) return targets diff --git a/salt/roster/ansible.py b/salt/roster/ansible.py index 2098b73129..14dd1dcf28 100644 --- a/salt/roster/ansible.py +++ b/salt/roster/ansible.py @@ -26,9 +26,9 @@ def targets(tgt, tgt_type='glob', **kwargs): Default: /etc/salt/hosts ''' if tgt == 'all': - tgt = '*': - if __opts__.get('inventory_file', False) is not False: - hosts = __opts__.get('inventory_file') + tgt = '*' + if __opts__.get('roster_file', False) is not False: + hosts = __opts__.get('roster_file') elif os.path.isfile(__opts__['conf_file']) or not os.path.exists(__opts__['conf_file']): hosts = os.path.join( os.path.dirname(__opts__['conf_file']), @@ -37,7 +37,7 @@ def targets(tgt, tgt_type='glob', **kwargs): hosts = os.path.join(__opts__['conf_file'], 'hosts') if os.path.isfile(hosts) and os.access(hosts, os.X_OK): - imatcher = Script(tgt, tgt_type='glob', hosts=hosts) + imatcher = Script(tgt, tgt_type='glob', inventory_file=hosts) else: imatcher = Inventory(tgt, tgt_type='glob', inventory_file=hosts) return imatcher.targets() @@ -56,7 +56,7 @@ class Inventory(object): blocks = re.compile('^\[.*\]$') hostvar = re.compile('^\[([^:]+):vars\]$') parents = re.compile('^\[([^:]+):children\]$') - with salt.utils.fopen(hosts) as config: + with salt.utils.fopen(inventory_file) as config: for line in config.read().split('\n'): if not line or line.startswith('#'): continue @@ -150,7 +150,7 @@ class Script(Inventory): ''' Matcher for Inventory scripts ''' - def __init__(self, inventory_file='/etc/salt/hosts2'): + def __init__(self, tgt, tgt_type='glob', inventory_file='/etc/salt/hosts'): self.tgt = tgt self.tgt_type = tgt_type inventory, error = subprocess.Popen([inventory_file], shell=True, stdout=subprocess.PIPE).communicate()