Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 'do update' pattern in map.jinja is not working properly for nested defaults when overriden by lookup #12

Closed
hkbakke opened this issue Oct 8, 2017 · 2 comments

Comments

@hkbakke
Copy link

hkbakke commented Oct 8, 2017

I think the map.jinja pattern is not working ideally as it is now as it completely falls apart if you have nested defaults.yaml file and you try to use lookup to change a single dictionary value somewhere in deeper levels of the default config.

The problematic part is the dictionary update where default_settings is updated with os_family_map as it does not do deep merging.

My main issue with this is not that I can't work around it, it's just that this template is for many seen as "best practice" and reused, and this issue is rather hard to diagnose as it works most of the time, until it just doesn't just because you added a lookup value to a formula with important nested defaults.

The most intuitive solution I have seen is using the base attribute of grains.filter_by. Is there any reason that the base attribute of grains.filter_by is not used today?

A pattern like this has none of these issues as far as I have experienced:

map.jinja:

# -*- coding: utf-8 -*-
# vim: ft=jinja

{## Start with defaults from defaults.yaml ##}
{% import_yaml 'template/defaults.yaml' as default_settings %}

{##
Setup variables using grains['os_family'] based logic, only add key:values
that differ from what is in defaults.yaml
##}
{% set base_settings = salt['grains.filter_by'](
  default_settings,
  , grain="os_family"
  , merge=salt['pillar.get']('template:lookup')
  , base='template')
%}

{## Merge in template:lookup pillar ##}
{% set template = salt['pillar.get'](
        'template',
        default=base_settings,
        merge=True
    )
%}

defaults.yaml:

# -*- coding: utf-8 -*-
# vim: ft=yaml
template:
  pkg: template
  config: '/etc/template'
  service:
    name: template

Debian: {}
Suse: {}
Arch:
  pkg: template-arch
RedHat:
  config: /etc/template.conf

An additional benefit is that since all the default settings is stored in defaults.yaml the os family map is much easier to write.

@aboe76
Copy link
Member

aboe76 commented Feb 10, 2019

see pr #20

@myii
Copy link
Member

myii commented Feb 24, 2019

@hkbakke Thanks for your report. This has been resolved by both #20 and #25.

@myii myii closed this as completed Feb 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants