【问题标题】:saltstack return inconsistent errorssaltstack 返回不一致的错误
【发布时间】:2021-12-23 03:52:45
【问题描述】:

Saltstack(版本=3004)最近在不同的 SLS 文件上返回了各种错误,而这些文件最近没有发生变化。不同的运行抱怨不同的文件,或者干脆成功。这发生在我们的 20 台主机上,而不仅仅是一台主机。我们在 ubuntu 20.04 LTS 主机上的无主上下文中使用 salt-call

关键是重新运行salt-call通常会成功,没有问题。如果没有,下一次运行将。之后的运行可能会失败,我们的 SLS 存储库中没有任何变化。似乎没有任何宇宙法则要求在成功之前先有这些失败,这更像是随机掷骰子。

不用说,到目前为止,在指示的位置查看 SLS 文件是没有结果的。

一些例子:

[myhost.example.com] sudo: salt-call --local state.highstate
[myhost.example.com] out: sudo password:
[myhost.example.com] out: [CRITICAL] Rendering SLS 'base:dulcia' failed: while parsing a block node
[myhost.example.com] out: did not find expected node content
[myhost.example.com] out:   in "<unicode string>", line 148, column 17
[myhost.example.com] out: local:
[myhost.example.com] out:     Data failed to compile:
[myhost.example.com] out: ----------
[myhost.example.com] out:     Rendering SLS 'base:dulcia' failed: while parsing a block node
[myhost.example.com] out: did not find expected node content
[myhost.example.com] out:   in "<unicode string>", line 148, column 17

另一个:

[otherhost.example.com] sudo: salt-call --local state.highstate
[otherhost.example.com] out: sudo password:
[otherhost.example.com] out: [CRITICAL] Rendering SLS 'base:dulcia' failed: did not find expected comment or line break
[otherhost.example.com] out: local:
[otherhost.example.com] out:     Data failed to compile:
[otherhost.example.com] out: ----------
[otherhost.example.com] out:     Rendering SLS 'base:dulcia' failed: did not find expected comment or line break

还有一个:

[host-3.example.com] sudo: salt-call --local state.highstate
[host-3.example.com] out: sudo password:
[host-3.example.com] out: [CRITICAL] Rendering SLS 'base:sftp' failed: while parsing a block node
[host-3.example.com] out: did not find expected node content
[host-3.example.com] out:   in "<unicode string>", line 235, column 17
[host-3.example.com] out: local:
[host-3.example.com] out:     Data failed to compile:
[host-3.example.com] out: ----------
[host-3.example.com] out:     Rendering SLS 'base:sftp' failed: while parsing a block node
[host-3.example.com] out: did not find expected node content
[host-3.example.com] out:   in "<unicode string>", line 235, column 17
[host-3.example.com] out: 

甚至

[host-3.example.com] sudo: salt-call --local state.highstate
[host-3.example.com] out: sudo password:
[host-3.example.com] out: [CRITICAL] Rendering SLS 'base:sftp' failed: did not find expected alphabetic or numeric character
[host-3.example.com] out: local:
[host-3.example.com] out:     Data failed to compile:
[host-3.example.com] out: ----------
[host-3.example.com] out:     Rendering SLS 'base:sftp' failed: did not find expected alphabetic or numeric character
[host-3.example.com] out: 

我对此完全不知所措,而且调试起来非常棘手,因为有一半以上的时间不会发生。

【问题讨论】:

    标签: salt-stack


    【解决方案1】:

    所以好消息。所有这些错误都是 yaml 渲染错误而不是 jinja。它们可能是由 jinja 渲染引起的,但 jinja 正在完成其渲染周期而不会引发错误。很可能某些值未设置为您认为的值。或者 jinja 没有在应该的时候提取正确的值。可能没有在应该设置的无主配置中设置支柱变量,然后在下次运行时设置它。或柱子渲染时间过长。

    开始调试的最简单方法是开始渲染 jinja 并验证生成的 yaml。这可以通过slsutil.renderer 完成

    salt-call slsutil.renderer salt://sftp/init.sls default_renderer=jinja
    

    由于问题是间歇性的,您将不得不一遍又一遍地渲染似乎最常失败的状态,直到它们失败。也许在长时间的停顿之后和运行高状态之前尝试。

    另一件可以帮助的事情是将日志记录插入到 jinja 中。这可以通过简单的{% do salt["log.info"]('string to log') %} 来完成,我发现这在 jinja 无法正确渲染的问题中很有用。

    还可以使用 -l debug 运行 highstate。它将显示每个 yaml 文件的渲染。这样您就可以看到正在发生的事情并看到正在发生的错误。

    【讨论】:

    • 谢谢,很有帮助,我试试。我对时间问题有点困惑:yaml 不等盐吗? (这是无服务器的。)
    • jinja 先渲染,渲染成yaml。 yaml 中的某些事情可能首先发生,例如包含。但这通常不是问题。一旦 jinja 成为渲染器,yaml 就会被解析为 python 数据,你在这里遇到了错误。一旦 yaml 被解析成 python,它就会被传递给状态系统。这对于无主控和有主控都是如此。
    • 以上建议让我找到了解决方案。问题的原因来自一个非常意想不到的来源:一个随机字符串的模板值。我们不是每次生成一个随机字符串并将其放入柱子中,而是懒惰地让 salt 每次都重新生成它(因为这并不重要,真的)。除了偶尔随机字符串包含 jinja 解释的内容,我们看到了一个错误。道德:salt 中的随机函数可能最好避免,或者至少要非常小心地注意默认选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    相关资源
    最近更新 更多