有没有办法让 saltstack 的行为像托管文件的傀儡?

Is there a way to make saltstack behave like puppet for managed files?

有没有办法让 saltstack 在管理配置文件时表现得像人偶一样。我要做的任务是让 sshd_config 被 saltstack 管理。如果对文件进行了更改,我希望 salt master 在主副本检测到托管配置文件不同或已被修改时通过推送主副本来覆盖它。这个设置可以使用 saltstack 吗?

有一个 file.managed 可能看起来像这样:

/etc/http/conf/http.conf:
  file.managed:
    - source: salt://apache/http.conf
    - user: root
    - group: root
    - mode: 644

每当您将此状态应用到 minion 时,Salt 都会将此文件传输到 minion。

从master上监控文件是可以实现的,但是这样做比较复杂。如果发生更改,您可以对 salt 事件总线使用 the reactor system of salt and write a small python program on the minion, which watches the file and fires an custom event。在 reactor 内部,您可以监听那些自定义事件并在 minion 上执行所需的状态。

请注意,如果您需要或多或少及时做出反应,这只是一个自定义解决方案(如果您真的想及时做出反应,所有这些都应该在 minion 内部完成,没有反应堆系统)。

请注意,在 salt 中更常见的方法是这样的:您在您最喜欢的时间间隔内为 minions 安排 highstates,并确保它们每 x 小时具有您想要的状态。