2015-10-25 24 views
3

我最近開始在我們的實驗室中使用Salt進行一些自動化操作。 我一直在嘗試測試自定義狀態,我可以自己寫。 我創建具有以下功能的簡單的測試:SaltStack,無法運行自定義狀態模塊

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

我還創建了一個SLS文件在/ SRV /鹽/ my_test .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文檔中的指南,但仍然無法弄清楚什麼是錯的。

+0

你是否嘗試過:'salt'*'saltutil.sync_states' – tudoricc

+0

是的,我做了,沒有幫助。 –

+0

您可以隨時爲master/minion啓用debug log_level並查看它是否找到您的文件。 –

回答

1

嘗試在在調試模式下在前臺一個終端中運行的僕從:

salt-minion -l debug 

然後在主運行:

salt '*' saltutil.sync_all 

salt win64-minion1 state.sls my_test 

檢查僕從輸出任何錯誤或蹤跡。

我知道這只是一個示例狀態,但通常狀態不應該自己寫出一個文件,而是使用Salt自己的執行模塊來寫入和讀取文件,否則會與您的操作系統進行交互。