有没有办法从 .sls 或 .jnija 文件中在 saltstack 中记录调试消息?

Ya.*_*Ya. 5 salt-stack

有没有办法从 .sls 或 .jnija 文件中在 saltstack 中记录自定义调试消息?即类似:

{% salt.log_message("Entering...") %}
Run Code Online (Sandbox Code Playgroud)

Ian*_*ang 8

使用添加状态test.nop并将要检查的内容添加为参数。

使用

salt-call -l debug state.apply yourslsfile test=True
Run Code Online (Sandbox Code Playgroud)

或者

salt-call --output=yaml state.show_sls yourslsfile
Run Code Online (Sandbox Code Playgroud)

检查结果。

例如:

调试文件

test:
  test.nop:
  - user: {{ grains.username }}
  - nested:
      foo: bar
Run Code Online (Sandbox Code Playgroud)

这是结果 state.show_sls

local:
  test:
    test:
    - user: ian
    - nested:
        foo: bar
    - nop
    - order: 10000
    __sls__: !!python/unicode dotfiles
    __env__: base
Run Code Online (Sandbox Code Playgroud)

最好设置一个独立的环境来测试状态,像这样


oeu*_*ete 8

这是在 2017.7.0 中作为一项功能添加的:

是的,在 Salt 中,可以使用日志调试复杂的 Jinja 模板。例如,拨打电话:

{%- do salt.log.error('testing jinja logging') -%}
Run Code Online (Sandbox Code Playgroud)

将在 minion 日志中插入以下消息:

2017-02-01 01:24:40,728 [salt.module.logmod][ERROR   ][3779] testing jinja logging
Run Code Online (Sandbox Code Playgroud)