Skip to main content

A Flexible External Salt Pillar Module

Project description

Salt Tower (Logo)

Salt Tower — A Flexible External Pillar Module

GitHub Workflow Status

Salt Tower is an advanced and flexible ext_pillar that gives access to pillar values while processing and merging them, can render all usual salt file formats and include private and binary files for a minion.

Salt Tower is inspired by pillarstack for merging pillar files and giving access to them. It also has a top file like salt itself and utilizes salt renderers to supports all formats such as YAML, Jinja, Python and any combination. Supercharged renderers for plain text and YAML are included too.

Each tower data file is passed the current processed pillars. They can therefore access previously defined values. Data files can include other files that are all merged together.

Salt Tower is designed to completely replace the usual pillar repository or can be utilized beside salts original pillar that e.g. can bootstrap a salt master with Salt Tower.

Questions or Need Help?

See examples. They each have their own README further explaining the given example.

There is a group and mailing list. You can join the group here or by sending a subscribe-email.

Feel free to ask for help, discuss solutions or ideas there. Otherwise, you can open an issue.



You can include this repository as a gitfs root and synchronize the extensions on the master:

  - base: v1.8.2

Sync all modules:

$ salt-run saltutil.sync_all
    - pillar.tower
    - renderers.filter
    - renderers.text
    - renderers.yamlet

Please note that everything in this repository would be merged with your other roots.


$ pip install salt-tower

Manual installation

Install the extension files from the salt_tower/{pillar,renderers} directories into the extension_modules directory configured in salt.


Salt Tower is configured as an ext_pillar:

  - tower: /path/to/tower.sls

Top File

The tower.sls file is similar to the usual top.sls with some important differences.

Ordered matchers

Pillar top items are ordered and processed in order of appearance. You can therefore define identical matchers multiple times.

# tower.sls
  - '*':
      - first

  - '*':
      - second
Common includes

You do not need to define a matcher at all, the files will be included for all minions. Furthermore, you also can use globs to match multiple files, e.g. include all files from common/.

  - common/*

The top file itself is rendered using the default renderer (yaml|jinja). Therefore, you can use e.g. grains to include specific files.

  - common/*
  - dist/{{ grains['oscodename'] }}
Embedded data

You can directly include pillar data into the top file simply be defining a dict item.

  - '*':
      - site:
          id: a
          name: A Site
Iterative pillar processing

All matchers are compound matchers by default. As items are processes in order of appearance, later items can patch on previously defined pillar values. The above example includes application.sls for any minion matching * simply because it defines a site pillar value.

  - '*':
      - site: {id: a, name: A Site}

  - 'I@site:*':
      - applications
Late-bound variable replacement

File includes are preprocessed by a string formatter to late-bind pillar values.

  - '*':
      - site: {id: a, env: production}

  - '*':
      - site: {id: a, env: staging}

  - 'I@site:*':
      - site/default
      - site/{}
      - site/{}/{site.env}/*

In the above example a minion will include the following files:

File lookup

File names will be matches to files and directories, e.g. when including path/to/file the first existing match will be used:


Tower Data File

A data file is processed like a usual pillar file. Rendering uses salts template engines therefore all usual features should be available.

The injected pillar objects can be used to access previously defined values. The additional .get method allows to traverse the pillar tree.

  title: Site of {{ pillar.get('tenant:name') }}

Note: Using salt['pillar.get']() will not work.

Tower data files can be any supported template format including python files:


def run():
    ret = {'databases': []}

    for app in __pillar__['application']:
            'name': '{0}-{1}'.format(app['name'], app['env'])

    return ret

Pillar data files can include other pillar files similar to how states can be included:

  - another/pillar

data: more

Included files cannot be used in the pillar data file template itself but are merged in the pillar before the new pillar data. Includes can be relative to the current file by prefixing a dot:

  - file/from/pillar/root.sls
  - ./adjacent_file.sls
  - ../parent_file.sls

Yamlet renderer

The Yamlet renderer is an improved YAML renderer that supports loading other files and rendering templates:

ssh_private_key: !read id_rsa
ssh_public_key: !read

This reads a file from the pillar directory in plain text or binary and embeds it into the pillar to e.g. ease shipping private file blobs to minions.

Using the !include tag files can be pushed through salts rendering pipeline on the server:

    my-app: !include ../files/site.conf
#!jinja | text strip
server {
  listen {{ pillar.get('my-app:ip') }}:80;
  root /var/www/my-app;

The pillar will return the following:

    my-app: |
      server {
        root /var/www/my-app;

This can greatly simplify states as they only need to drop pillar values into config files and restart services:

  pkg.installed: []
  service.running: []

{% for name in pillar.get('nginx:sites', {}) %}
/etc/nginx/sites-enabled/{{ name }}:
    - contents_pillar: nginx:sites:{{ name }}
    - makedirs: True
    - watch_in:
      - service: nginx
{% endfor %}

The yamlet renderer !include macro does accept context variables too:

    my-app: !include
      source: ../files/site.conf
#!jinja | text strip
server {
  listen {{ listen_ip }}:80;
  root /var/www/my-app;

Text renderer

The text renderer (used above) renders a file as plain text. It stripes the shebang and can optionally strip whitespace from the beginning and end.

#!text strip

Hello World

This will return:

Hello World

The text renderer is mostly used for embedding rendered configuration files into a Yamlet file.

Filter renderer

The filter renderer returns only a subset of data that matches a given grain or pillar key value:

#!yamlet | filter grain=os_family default='Unknown OS'

  package_source: apt

  package_source: rpm

Unknown OS:
  package_source: unknown

When this file is rendered, only the data from the matching top level key is returned. The renderer supports glob matches and uses the minion ID by default:

#!yamlet | filter

    type: ping

    type: http

Advanced usage (very dangerous)

The pillar object passed to the python template engine is the actual mutable dict reference used to process and merge the data. It is possible to modify this dict e.g. in a python template without returning anything:


import copy

def run():
    databases = __pillar__['databases']
    default = databases.pop('default') # Deletes from actual pillar

    for name, config in databases.items():
        databases[name] = dict(default, **config)

    return {}

Note 1: Do not return None. Otherwise, Salt will render the template twice and all side effects will be applied twice.

Note 2: The __pillar__ object in Python templates is different to other template engines. It is a dict and does not allow traversing using get.


def run():
    return {
        'wrong': __pilar__.get('tenant:name'),
        'python': __pillar__['tenant']['name'],
        'alternative': tower.get('tenant:name')

The above example demonstrates different usages. The first example will only work if the pillar contains an actual tenant:name top-level key. The second example is idiomatic-python but will raise an error if the keys do not exist. The third example uses the additional tower helper module to traverse the pillar data.

The tower pillar object is available in all rendering engines and can be used for low-level interaction with the ext_pillar engine. Some available functions are:

tower.get(key, default=None, require=False)

Get a pillar value by given traverse path:


If require=True is set, default will be ignored and a KeyError will be raised if the pillar key is not found.


Merges given dictionary into the pillar data.

tower.update({'my': {'pillar': 'data'}})

assert tower.get('my:pillar') == 'data'
tower.merge(tgt, *objects)

Merges given dictionaries or lists into the first one.

Note: The first given dictionary or list is mutated and returned.

tgt = {}

ret = tower.merge(tgt, {'a': 1})

assert ret is tgt
assert tgt['a'] == 1
tower.format(obj, *args, **kwargs)

Performs recursive late-bind string formatting using tower pillar and given arguments ad keywords for resolving. Uses string.Formatter internally.

    'database': {
        'password': 'secret'

ret = tower.format('postgres://user@{database.password}/db')

assert ret == 'postgres://user@secret/db'

Format accept dictionaries and list as well and can therefore be used to format full or partial pillar data, this can be used to e.g. format defaults with extra variables:


def run():
    returns = {}
    defaults = __pillar__['default_app_config']
    # e.g. {
    #        'database': 'sqlite:///opt/{name}.sqlite'
    #        'listen': '{app.port}'
    # }

    for name, conf in __pillar__['applications'].items():
        # Merge defaults with conf into new dictionary
        conf = tower.merge({}, defaults, conf)

        # Format late-bind defaults with application config
        conf = tower.format(conf, name=name, app=conf)

        returns[name] = conf

    return {'applications': returns}

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

salt-tower-1.9.0.tar.gz (23.3 kB view hashes)

Uploaded source

Built Distribution

salt_tower-1.9.0-py3-none-any.whl (23.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page