Search code examples
salt-stackconfiguration-management

Purpose of empty brackets in Saltstack state definitions?


What's the purpose of empty brackets after SaltStack state definitions?

For example, somewhere in SaltStack documentation you'll see this:

vim:
  pkg.installed: []

Yet enforcing, for example, vim installation could also be expressed like so:

vim:
  pkg.installed

.. and indeed, elsewhere in SaltStack documentation that is the prevailing format. So what do the empty brackets signify? Explicitly stating that there are no further parameters for that statement?


Solution

  • The short answer to your question is: yes. They just explicitly state that there are no additional parameters to pkg.installed.

    The long answer: Salt .sls format is basically a YAML with Jinja templates on top. This means each item in the configuration is either a sequence or a collection. In your example pkg.installed has number of optional parameters that can be supplied as a sequence of collections ( think of it as of array of dicts in other programming languages ). For example you could've make the vim version fixed like this:

    vim:
      pkg.installed:
        - version: 1.0
    

    YAML allows two syntaxes for writing down sequences and collections. The one described above can also be written as:

    vim:
      pkg.installed: [{version: 1.0}]
    

    In your example the pkg.installed does not have any additional parameters supplied and that's explicitly shown with empty square brackets.