是否有办法从.sls或.jinja文件中记录saltstack中的调试消息?



是否有办法在saltstack中从.sls或.jinja文件中记录自定义调试消息?例如:

{% salt.log_message("Entering...") %}

这是作为2017.7.0的功能添加的:

是的,在Salt中,可以使用日志例如,调用

{%- do salt.log.error('testing jinja logging') -%}

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

2017-02-01 01:24:40,728 [salt.module.logmod][ERROR   ][3779] testing jinja logging

使用test.nop添加一个状态,并添加您想要检查的东西作为参数。

使用

salt-call -l debug state.apply yourslsfile test=True

salt-call --output=yaml state.show_sls yourslsfile

检查结果。

例如:

debug.sls

test:
  test.nop:
  - user: {{ grains.username }}
  - nested:
      foo: bar

这是state.show_sls

的结果
local:
  test:
    test:
    - user: ian
    - nested:
        foo: bar
    - nop
    - order: 10000
    __sls__: !!python/unicode dotfiles
    __env__: base
最好设置一个独立的环境来测试状态,如下所示

最新更新