Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to log a debug message in saltstack out of an .sls or a .jnija file?

Tags:

salt-stack

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...") %}
like image 783
Ya. Avatar asked Nov 01 '16 19:11

Ya.


People also ask

Where can I find salt logs?

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.


2 Answers

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
like image 153
oeuftete Avatar answered Sep 23 '22 04:09

oeuftete


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

like image 43
Ian Yang Avatar answered Sep 25 '22 04:09

Ian Yang