salt.modules.defaults

Module to work with salt formula defaults files

salt.modules.defaults.deepcopy(source)

Allows deep copy of objects in formulas.

By default, Python does not copy objects, it creates bindings between a target and an object.

It is more typical to use this in a templating language in formulas, instead of directly on the command-line.

salt.modules.defaults.get(key, default='')

defaults.get is used much like pillar.get except that it will read a default value for a pillar from defaults.json or defaults.yaml files that are stored in the root of a salt formula.

CLI Example:

salt '*' defaults.get core:users:root

The defaults is computed from pillar key. The first entry is considered as the formula namespace.

For example, querying core:users:root will try to load salt://core/defaults.yaml and salt://core/defaults.json.

salt.modules.defaults.merge(dest, src, merge_lists=False, in_place=True, convert_none=True)

Allows deep merging of dicts in formulas.

merge_listsFalse

If True, it will also merge lists instead of replace their items.

in_placeTrue

If True, it will merge into dest dict, if not it will make a new copy from that dict and return it.

convert_noneTrue

If True, it will convert src and dest to empty dicts if they are None. If True and dest is None but in_place is True, raises TypeError. If False it will make a new copy from that dict and return it.

New in version 3005.

CLI Example:

salt '*' defaults.merge '{a: b}' '{d: e}'

It is more typical to use this in a templating language in formulas, instead of directly on the command-line.

salt.modules.defaults.update(dest, defaults, merge_lists=True, in_place=True, convert_none=True)

Allows setting defaults for group of data set e.g. group for nodes.

This function is a combination of defaults.merge and defaults.deepcopy to avoid redundant in jinja.

Example:

group01:
  defaults:
    enabled: True
    extra:
      - test
      - stage
  nodes:
    host01:
      index: foo
      upstream: bar
    host02:
      index: foo2
      upstream: bar2
{% do salt['defaults.update'](group01.nodes, group01.defaults) %}

Each node will look like the following:

host01:
  enabled: True
  index: foo
  upstream: bar
  extra:
    - test
    - stage
merge_listsTrue

If True, it will also merge lists instead of replace their items.

in_placeTrue

If True, it will merge into dest dict. if not it will make a new copy from that dict and return it.

convert_noneTrue

If True, it will convert src and dest to empty dicts if they are None. If True and dest is None but in_place is True, raises TypeError. If False it will make a new copy from that dict and return it.

New in version 3005.

It is more typical to use this in a templating language in formulas, instead of directly on the command-line.