SaltStack,无法运行自定义状态模块

时间:2015-10-25 08:05:27

标签: salt-stack

我最近开始在我们的实验室中使用Salt进行自动化。 我一直试图测试我可以自己写的自定义状态。 我使用以下函数创建了一个简单的测试:

def write_text(text, where):

        ret = {'text': text, 'where': where, 'result': False}
        try:
                with open(r''+where, 'w') as file:
                        file.write('this is a test')
                ret['result'] = True
        except:
                ret['result'] = False
        return ret

我将该文件放在/srv/salt/_states/my_test.py

我还在/srv/salt/my_test.sls

创建了一个sls文件
#Test custom state module
custom_state_test:
  my_test:
    - write_text
    - text: 'this is a test'
    - where: 'C:\text.txt'

但是每当我使用salt win64-minion1 state.sls my_test在一个小兵上运行它 (我的爪牙是Windows机器)我收到以下错误

win64-minion1:
----------
          ID: custom_state_test
    Function: my_test.write_text
      Result: False
     Comment: State 'my_test.write_text' was not found in SLS 'my_test'
              Reason: 'my_test.write_text' is not available.
     Started:
    Duration:
     Changes:

我已经按照SaltStacks文档的指南进行了操作,但仍然无法弄清楚错误。

1 个答案:

答案 0 :(得分:1)

尝试在调试模式下在前台终端中运行minion:

salt-minion -l debug

然后在主跑上:

salt '*' saltutil.sync_all

salt win64-minion1 state.sls my_test

检查minion输出是否有任何错误或堆栈痕迹。

我知道这只是一个示例状态,但通常状态不应该自己写出文件,而是使用Salt自己的执行模块来编写和读取文件,否则会与操作系统进行交互。