Is there a way to log a custom debug message in saltstack out of an .sls or a .jnija file? i.e. something like:
{% salt.log_message("Entering...") %}
You can set the log location by editing your SaltStack configuration file on the salt-master. By default, this file should be located at /etc/salt/master on most Unix-like systems.
This was added as a feature in 2017.7.0:
Yes, in Salt, one is able to debug a complex Jinja template using the logs. For example, making the call:
{%- do salt.log.error('testing jinja logging') -%}Will insert the following message in the minion logs:
2017-02-01 01:24:40,728 [salt.module.logmod][ERROR ][3779] testing jinja logging
Add a state using test.nop and add things you want to inspect as arguments to it.
The use
salt-call -l debug state.apply yourslsfile test=True
or
salt-call --output=yaml state.show_sls yourslsfile
to check the result.
For example:
debug.sls
test:
  test.nop:
  - user: {{ grains.username }}
  - nested:
      foo: bar
Here is the result of state.show_sls
local:
  test:
    test:
    - user: ian
    - nested:
        foo: bar
    - nop
    - order: 10000
    __sls__: !!python/unicode dotfiles
    __env__: base
It is better to setup a standalong environment to test states, like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With