def ext_pillar(self, pillar, errors=None): ''' Render the external pillar data ''' if errors is None: errors = [] try: # Make sure that on-demand git_pillar is fetched before we try to # compile the pillar data. git_pillar will fetch a remote when # the git ext_pillar() func is run, but only for masterless. if self.ext and 'git' in self.ext \ and self.opts.get('__role') != 'minion': # Avoid circular import import salt.utils.gitfs import salt.pillar.git_pillar git_pillar = salt.utils.gitfs.GitPillar( self.opts, self.ext['git'], per_remote_overrides=salt.pillar.git_pillar. PER_REMOTE_OVERRIDES, per_remote_only=salt.pillar.git_pillar.PER_REMOTE_ONLY, global_only=salt.pillar.git_pillar.GLOBAL_ONLY) git_pillar.fetch_remotes() except TypeError: # Handle malformed ext_pillar pass if 'ext_pillar' not in self.opts: return pillar, errors if not isinstance(self.opts['ext_pillar'], list): errors.append('The "ext_pillar" option is malformed') log.critical(errors[-1]) return pillar, errors ext = None # Bring in CLI pillar data if self.pillar_override: pillar = merge(pillar, self.pillar_override, self.merge_strategy, self.opts.get('renderer', 'yaml'), self.opts.get('pillar_merge_lists', False)) for run in self.opts['ext_pillar']: if not isinstance(run, dict): errors.append('The "ext_pillar" option is malformed') log.critical(errors[-1]) return {}, errors if next(six.iterkeys(run)) in self.opts.get( 'exclude_ext_pillar', []): continue for key, val in six.iteritems(run): if key not in self.ext_pillars: log.critical( 'Specified ext_pillar interface %s is unavailable', key) continue try: ext = self._external_pillar_data(pillar, val, key) except Exception as exc: errors.append('Failed to load ext_pillar {0}: {1}'.format( key, exc.__str__(), )) log.error( 'Exception caught loading ext_pillar \'%s\':\n%s', key, ''.join(traceback.format_tb(sys.exc_info()[2]))) if ext: pillar = merge(pillar, ext, self.merge_strategy, self.opts.get('renderer', 'yaml'), self.opts.get('pillar_merge_lists', False)) ext = None return pillar, errors
def ext_pillar(self, pillar, errors=None): """ Render the external pillar data """ if errors is None: errors = [] try: # Make sure that on-demand git_pillar is fetched before we try to # compile the pillar data. git_pillar will fetch a remote when # the git ext_pillar() func is run, but only for masterless. if self.ext and "git" in self.ext and self.opts.get( "__role") != "minion": # Avoid circular import import salt.utils.gitfs import salt.pillar.git_pillar git_pillar = salt.utils.gitfs.GitPillar( self.opts, self.ext["git"], per_remote_overrides=salt.pillar.git_pillar. PER_REMOTE_OVERRIDES, per_remote_only=salt.pillar.git_pillar.PER_REMOTE_ONLY, global_only=salt.pillar.git_pillar.GLOBAL_ONLY, ) git_pillar.fetch_remotes() except TypeError: # Handle malformed ext_pillar pass if "ext_pillar" not in self.opts: return pillar, errors if not isinstance(self.opts["ext_pillar"], list): errors.append('The "ext_pillar" option is malformed') log.critical(errors[-1]) return pillar, errors ext = None # Bring in CLI pillar data if self.pillar_override: pillar = merge( pillar, self.pillar_override, self.merge_strategy, self.opts.get("renderer", "yaml"), self.opts.get("pillar_merge_lists", False), ) for run in self.opts["ext_pillar"]: if not isinstance(run, dict): errors.append('The "ext_pillar" option is malformed') log.critical(errors[-1]) return {}, errors if next(iter(run.keys())) in self.opts.get("exclude_ext_pillar", []): continue for key, val in run.items(): if key not in self.ext_pillars: log.critical( "Specified ext_pillar interface %s is unavailable", key) continue try: ext = self._external_pillar_data(pillar, val, key) except Exception as exc: # pylint: disable=broad-except errors.append("Failed to load ext_pillar {}: {}".format( key, exc.__str__(), )) log.error( "Exception caught loading ext_pillar '%s':\n%s", key, "".join(traceback.format_tb(sys.exc_info()[2])), ) if ext: pillar = merge( pillar, ext, self.merge_strategy, self.opts.get("renderer", "yaml"), self.opts.get("pillar_merge_lists", False), ) ext = None return pillar, errors