'Add container tags to instance templates and build a
dict from template variable names and their values.'

def _fill_tpl(self, state, c_id, instance_tpl, variables, tags=None):

    var_values = {}
    c_image = state.inspect_container(c_id).get('Config', {}).get('Image', '')
    if tags:
        tpl_tags = instance_tpl.get('tags', [])
        if isinstance(tpl_tags, dict):
            for (key, val) in tpl_tags.iteritems():
                tags.append('{}:{}'.format(key, val))
        else:
            tags += (tpl_tags if isinstance(tpl_tags, list) else [tpl_tags])
        instance_tpl['tags'] = list(set(tags))
    for var in variables:
        if (var.split('_')[0] in self.VAR_MAPPING):
            try:
                res = self.VAR_MAPPING[var.split('_')[0]](state, c_id, var)
                if (res is None):
                    raise ValueError(('Invalid    value    for    variable    %s.' % var))
                var_values[var] = res
            except Exception as ex:
                log.error(('Could    not    find    a    value    for    the    template    variable    %s    for    container    %s    (%s):    %s' % (var, c_id[:12], c_image, str(ex))))
        else:
            log.error(('No    method    was    found    to    interpolate    template    variable    %s    for    container    %s    (%s).' % (var, c_id[:12], c_image)))
    return (instance_tpl, var_values)
