map

Provide helpers to render layered formula configuration.

This is heavily based on the excellent work done in the template-formula.

saltext.formula.modules.map.data(tpldir, sources=None, parameter_dirs=None, config_get_strategy=None, default_merge_strategy=None, default_merge_lists=False, post_map='post-map.jinja', post_map_template='jinja', cache=True, custom_data=None)[source]

Render formula configuration.

Note

This function is intended to be called from templates during the rendering of states, but it can be used for debugging/information purposes as well.

CLI Example:

salt '*' map.data openssh
tpldir

Pass tpldir from the state file. Used to derive the tplroot, which is currently always the first part of the path.

sources

A list of default data source definitions. Can be overridden globally or per-formula. Earlier entries have a lower priority (later ones are merged on top).

Defaults to:

- Y!P@defaults.yaml
- Y!G@osarch
- Y!G@os_family
- Y!G@os
- Y!G@osfinger
- C@{tplroot}
- Y!G@id

Important

defaults.yaml is always prepended to the list, you don’t need to include it.

parameter_dirs

A list of default parameter directories to look up YAML parameter files in. Can be overridden globally or per-formula.

Defaults to [{tplroot}/parameters], where tplroot is the first part of tpldir.

config_get_strategy

A merge strategy used in calls to config.get. Can be overridden globally or per-formula. Defaults to None.

default_merge_strategy

A default merge strategy for this formula. See slsutil.merge for available ones. Can be overridden globally or per-formula. Defaults to smart.

default_merge_lists

Whether to merge lists by default in this formula. Can be overridden globally or per-formula. Defaults to false.

post_map

Allow a template with this path relative to the formula root directory to modify the final result before returning. See post-map.jinja for details. Can be overridden globally or per-formula. Defaults to post-map.jinja. False disables this behavior.

post_map_template

The renderer required for the template specified in post_map. Can be overridden globally or per-formula. Defaults to jinja.

cache

Whether to cache the result for subsequent calls with the same arguments. Can be overridden globally or per-formula. Enabled by default.

custom_data

Added in version 0.3.0.

A custom dictionary that can provide values for the U matcher. Must be picklable.

saltext.formula.modules.map.stack(tpldir, sources, parameter_dirs=None, default_values=None, default_merge_strategy=None, default_merge_lists=None, config_get_strategy=None, custom_data=None)[source]

Takes a list of matcher definitions and renders the resulting layered configuration.

CLI Example:

salt '*' map.stack openssh '[defaults.yaml, Y@G:os]'
tpldir

Pass tpldir from the state file.

sources

A list of data source (matcher) definitions.

parameter_dirs

A list of parameter directories to look up YAML files in. Defaults to [{tplroot}/parameters, parameters], where tplroot is the first part of tpldir.

default_values

Provide default values.

default_merge_strategy

Provide a default value for merge_strategy when merging results into the stack.

default_merge_lists

Provide a default value for merge_lists when merging results into the stack.

config_get_strategy

A merge strategy used in calls to config.get. Defaults to None.

custom_data

Added in version 0.3.0.

A custom dictionary that can provide values for the U matcher.

saltext.formula.modules.map.tofs(tpldir, source_files, lookup=None, default_matchers=None, use_subpath=False, include_query=True, path_prefix=None, files_dir='files', default_dir='default', config=None, custom_data=None)[source]

Render a list of TOFS patterns to be used as an input to states that allow to specify multiple sources, such as file.managed.

Note

This function is intended to be called from templates during the rendering of states, but it can be used for debugging/information purposes as well.

CLI Example:

salt '*' map.tofs openssh '[salt.conf, salt.conf.jinja]'
salt '*' map.tofs openssh '[etc/salt/master, etc/salt/master.j2]'
tpldir

Pass tpldir from the state file.

source_files

A list of relative paths to render relative to all TOFS sources. Earlier entries have a higher priority (they are searched first). Required.

lookup

Allow users to specify alternate file names in the formula configuration that are prepended to the default source_files (in tofs:source_files:<lookup>).

default_matchers

A list of data source (matcher) definitions. Can be overridden in tofs:files_switch, which itself can also be overridden per subpath (eg sub/path), including the root one, in <sub>:<path>:files_switch.

use_subpath

When called from a state inside a nested directory, e.g. salt://salt/minion/config/init.sls, also try files_dir relative to each parent (salt/minion/config/files, salt/minion/files, salt/files). Defaults to false.

include_query

Include the matcher query in the path. Defaults to true. When true: G@os -> files/os/Fedora/salt.conf When false: G@os -> files/Fedora/salt.conf

path_prefix

The path prefix containing the files_dir. Defaults to the first part of tpldir.

files_dir

The directory relative to path_prefix containing possible files. Defaults to files.

default_dir

The name of the directory that is used as a fallback. Defaults to default.

config

If you have rendered the formula configuration, you can pass it here. If not passed, calls map.data <saltext.formula.modules.map.data() to fetch it.

custom_data

Added in version 0.3.0.

A custom dictionary that can provide values for the U matcher.