Skip to content

Instantly share code, notes, and snippets.

View Sjd-Risca's full-sized avatar

Riccardo Scartozzi (risca) Sjd-Risca

View GitHub Profile
@Sjd-Risca
Sjd-Risca / Jinja2 saltstack: dictionary merging
Created April 19, 2016 09:11
For Saltstack with jinja rendering: deep merge a dictionary into a first one
{%- macro deep_merge(a, b) %}
{%- for k,v in b.iteritems() %}
{%- if v is string or v is number %}
{%- do a.update({ k: v }) %}
{%- elif v is not mapping %}
{%- if a[k] is not defined %}
{%- do a.update({ k: v }) %}
{%- elif a[k] is iterable and a[k] is not mapping and a[k] is not string %}
{%- do a.update({ k: v|list + a[k]|list}) %}
{%- else %}