Salt-Lint
Salt-lint is a command-line utility that checks Salt State files (SLS) for best practices and potential improvements in SaltStack environments. Heavily inspired by `ansible-lint`, it helps enforce coding standards and identify common pitfalls in Salt configurations. It is currently at version 0.9.2 and maintains an active release cadence, with multiple bugfix and feature releases per year.
Warnings
- breaking Python 2.7 support was officially dropped in version 0.6.0. Users on older Python environments must upgrade to Python 3.6 or newer to use current versions of salt-lint.
- gotcha New linting rules are frequently added, and existing rules may be modified or removed, which can lead to changes in linting output and new errors appearing after an upgrade. For example, rule 218 was removed in v0.6.1, and rule 210 was reverted in v0.9.1.
- gotcha SLS files with periods in their name (other than the `.sls` suffix) are not correctly referenced by Salt. Salt-lint introduced rule 214 in v0.5.0 to detect this naming convention.
- gotcha Earlier versions could produce false positives when detecting missing spaces in Jinja variables if the Jinja statement was nested in literal braces. This was fixed in version 0.8.0.
- gotcha Incorrect quotation or missing leading zeros in file modes (e.g., `mode: 755` instead of `mode: '0755'`) can lead to unintended permissions. Salt-lint fixed several false positives and improved detection for these in version 0.8.0.
Install
-
pip install salt-lint
Quickstart
mkdir -p my_salt_states
echo 'my_package:
pkg.installed:
- name: vim
- version: latest
- onchanges:
- file: /etc/vimrc
my_service:
service.running:
- name: apache2
- enable: True
- watch:
- pkg: my_package' > my_salt_states/init.sls
salt-lint my_salt_states/init.sls