A Cookiecutter template that initializes a project structure for developing Salt extension modules.
The template files themselves are currently sourced almost verbatim from the official create-salt-extension tool. This template provides the necessary scaffolding to render them via Cookiecutter (using some ugly hacks).
I like to manage the lifecycle of my projects via cruft, which wraps Cookiecutter to additionally provide (1) boilerplate updates after the initial project generation and (2) diffs of what you changed versus the generated data.
You will need to specify the loaders
argument as a comma-separated string of module types to generate (singular or plural forms are allowed, spaces ignored).1 The following module types are available:
auth
beacon
cache
cloud
engine
executor
fileserver
grain
log_handler
matcher
metaproxy
module
netapi
output
pillar
pkgdb
pkgfile
proxy
queue
renderer
returner
roster
runner
sdb
serializer
state
thorium
token
top
wheel
wrapper
The recommended way to use this template is with cruft. Once this tool is available, creating an extension can be as simple as running:
$ cruft create https://github.com/lkubb/salt-extension-cookiecutter
You will be asked several questions, after which the project skeleton should be available. It will additionally contain a .cruft.json
file with the inputs you gave and the most recent commit hash of the template repository that was used when creating it.
Future boilerplate updates can be as simple as:
$ cruft update
And you can show a diff of the current state of the code versus the boilerplate at the time of generation by running:
$ cruft diff
This also allows you to modify the inputs in .cruft.json
and apply them (to existing files). But: The following command will reset your changes to all known files! So better filter the output manually if you already started your work.
$ cruft diff | git apply # resets all changes on existing files!
You could just use the official tool instead. :)
Otherwise:
$ git clone https://github.com/lkubb/salt-extension-cookiecutter
$ cookiecutter salt-extension-cookiecutter
- The official tool is found here: https://github.com/saltstack/salt-extension
- The
salt-extensions
organization: https://github.com/salt-extensions cruft
docs: https://cruft.github.io/cruft/cookiecutter
docs: https://cookiecutter.readthedocs.io/en/stable/index.html- An overview of modular systems in Salt: https://docs.saltproject.io/en/latest/topics/development/modules/index.html
- The Salt-specific
pytest
docs: https://pytest-salt-factories.readthedocs.io/en/latest/
Footnotes
-
Sadly Cookiecutter does not support multichoice variables via its interactive prompt currently. ↩