2016-10-05 6 views
-1

私は、次のタスクとハンドラのセクション(ちょうどスニペット)と脚本を持っている:Ansibleハンドラとシェルモジュール

tasks: 
    - name: 'Run legacy script and power off' 
     debug: msg="Preparing for reboot" 
     notify: Legacy sysprep 

    handlers: 
    - name: Enable Service1 
     service: name=service1 enabled=yes state=restarted 

    - name: Legacy sysprep 
     shell: /var/scripts/prep-reboot.sh 

私は脚本を実行すると、私はLegacy sysprepを呼び出しタスクのデバッグメッセージを参照してくださいハンドラが実行されていますが、Enable Service1ハンドラが実行されていますが、Legacy sysprepハンドラが呼び出されていない(プレイブックの出力には表示されず、システムでも実行されません)、サーバはリブートされません(スクリプトの一部) 。

はい、私はprep-reboot.shスクリプトをAnsibleプレイブックに移行する予定ですが、明らかにshellモジュールが機能していないようです。それとも私が見落としたエラーはありますか? -vvvで実行しても、予期しないことは報告されません。

RHEL 6.8で実行される、安全で安心できるプレイブックバージョン2.1.1.0。

+1

は、あなたが与えられている例で実行するためのハンドラのいずれかのための方法はありません。それは、質問は理解できないと言いました。 **確認可能な**例を提供してください。 – techraf

+0

@techraf - ヒントをお寄せいただきありがとうございます。私は "changed_when:true"をプレイに追加しました。今度はハンドラがトリガします。私が下に投稿した答えを見てください。 –

答えて

0

ありがとうございます、@テフラフ私は正しい方向に指摘しました。私はchanged_when: trueをデバッグ行に追加してしまい、それがその再生を強制して変更を登録してから、適切なハンドラをトリガします。

は、ここに参照のための私の実際の試験脚本です:DEBUG`は `ok`状態を返します`ので

--- 
- name: Testing forced handler 
    hosts: testsys_only 
    gather_facts: True 

    tasks: 
    - name: 'Run legacy script and power off' 
     debug: msg="Preparing for reboot" 
     changed_when: true 
     notify: Legacy sysprep 

    handlers: 
    - name: Enable Service1 
     service: name=service1 enabled=yes state=restarted 

    - name: Legacy sysprep 
     shell: /var/scripts/prep-reboot.sh