I'm working currently on Saltstack and I didn't find my answer on the documentation nor the examples.
So I just wonder if it is possible to templatize top.sls file, aka highstate file with some Jinja2 templating?
For instance, I would apply a state on a machine depending on some values in the pillar that I provide in vagrant using the salt provisioner. I tried and it looks like it doesn't work, the jinja in the topfile looks like it's not been rendered.
Is there a way using the match keyword for example?
In top.sls, you can use Jinja. We use it, for example, to retrieve pillar values with salt['pillar.get'] and include different states depending of those pillar.
Related
Say I have a directory utility_configs that has a bunch of different configurations for different things that are useful in different situations. And then I want to be able to use these different configs in different places. For instance, maybe my model has many different places where I need something that is an "encoder" (really just a bit of network that maps an input to an output). I might have vary different encoders in my utility_configs directory, and I would like to be able to specify any of them anyplace I need an encoder (possibly then adjusting the number of input and output channels or other parameters). I am not seeing how to do this straightforwardly since it seems like the only way you can get data from a different file is using the defaults list. But that's not really a good fit here since I might need multiple different things from utility_configs and in multiple different places (including subconfigs)
You cannot interpolate into a file. Interpolation works on the current config object.
Hydra can compose the config for you, after which you can use interpolation.
You have multiple options:
Have more than one primary config (with a defaults list). You can override which primary config to use via the command line (--config-name|-cn).
Construct your defaults list in an ad-hoc manner via the command line using the +GROUP=OPTION notation (see this).
About using a config in different places, take a look at config packages - which allows you to relocate the content of a config in the composed config object.
I recommend going with 1.
Somewhat new to salt here. I set up salt and managed to get everything working rather nicely. After the setup, I decided to try make small state files and run those from another state file. The main reason being ease of troubleshooting/changing a small file vs. troubleshooting a huge state file. Unfortunately, outside of the top file, I haven't been successful in getting a state to be called from another state.
For example, let's say I have foo.sls and bar.sls, and bar.sls is a state that installs packages properly. I have tried the following.
#foo.sls
packages:
state.apply:
- source: salt://packages/bar.sls
Also
#foo.sls
packages/bar.sls:
state.apply
And also
#foo.sls
state.apply:
- source: salt://packages/bar.sls
And few others that I'm not remembering right now.
Most times I've tried though, I get an error stating that state.apply is not available, leading me to believe this is either not possible, or I'm going about it wrong.
Can this be done? If so, how? If not, maybe I'll file a feature request for this, as it seems like it could be useful.
background
It sounds like your issue may stem from mixing state modules and execution modules when you are writing your states.
Brief recap, "states" are the declarative files you write (foo.sls, bar.sls), "state modules" are the directives you list inside those states (e.g. pkg.installed), and "execution modules" provide the commands that salt actually knows how to run (state.apply, test.ping, etc.).
state.apply is simply the execution module that knows how to interpret states. It may help to note that the fully qualified name of state.apply from the docs (or if you browse the salt source tree) is actually salt.modules.state.apply, whereas pkg.installed is salt.states.pkg.installed. A module in the modules namespace generally cannot be accessed from states namespace and vice versa, though there are exceptions. Knowing the full namespace is also a necessary distinction when an execution module and a state modules share a virtual name, e.g. test exists as both salt.modules.test and salt.states.test.
solution
If I understand correctly, you probably want to include your state files within each other.
For example, say you have the following folder structure:
$ tree srv
srv
└── salt
├── foo.sls
└── packages
└── bar.sls
and bar.sls has the following contents
# bar.sls
packages_bar_install_fun:
pkg.installed:
- pkgs:
- cowsay
- fortune
- sl
To include bar.sls into foo.sls you just need to reference it using dot notation, depending on your folder structure
# foo.sls
include:
- packages.bar
foo_another_example_state:
test.show_notification:
- text: |
foo.sls can have other states inside of it,
though you may need to use `require` if you want
them interspersed between multiple includes
Now you can either just include - foo in your top.sls, or run salt '<tgt>' state.apply foo test=True and you should see that package.bar would also be applied.
The salt docs also include a section titled Moving Beyond a Single SLS which discusses using include and extend to glue multiple states together.
Splitting up an SLS for organizational purposes is also a common use for init.sls
As a brief aside, there are some states which go the other direction and allow allow you to run execution modules from within an SLS. A few examples are salt.states.module.run and salt.states.saltmod.state, though the uses for these are far more specialized than what it seems you're trying to do.
I am working on a project that is using the multiline node package. This allows us to create multi-line strings inside of multi-line comment tags.
The problem I am encountering is related to the grunt-jasmine-node-coverage node package.
Normally running istanbul, you can pass in the flag --preserve-comments and it won't strip out comments while processing the coverage information, otherwise it will default to false.
So far I have not been able to find a workaround for passing in this flag in the grunt-jasmine-node-coverage configuration. Is what I am trying to accomplish currently possible?
I use the jsqueeze assets filter for my project and digged in the code.
For me, it seems like the squeeze() function is beign called on the js files given.
Now i want to set the renaming variables argument on the squeeze function, but it is a third-party-bundle and i haven't found a solution to configure it in the config.yml where the filter is defined.
I found out where the magic happens.
All possible configurations are stored in the symfony assetics-bundle:
vendor>symfony>assetics-bundle>Resources>config>filters
For each filter, there is an xml file with the parameters you are able to change.
It took me a lot of time to find this, i think it is not documented in the symfony documentation.
In Flyway is there any way to mark certain scripts for inclusion or exclusion? What I am looking for is something similar to Liquibase's 'contexts' feature, or Dbmaintains 'qualifiers'. My primary use case is the test one that is outlined on the Liquibase site, a 'test' context where only scripts that are related to test data will run.
Yes. Put those test scripts in a second folder, and selectively configure flyway.locations to include it.