2017-02-15 2 views
0

私はthe following tasksありan Ansible role持っている:すなわちタスクの失敗に関係なくハンドラを実行しますか?

--- 
# optionally find the latest version of goss using the GitHub "API" 
- name: detect latest version 
    shell: | 
    curl -sIS https://github.com/aelsabbahy/goss/releases/latest | \ 
     tr -d '\r' | \ 
     grep -oP '(?<=Location:\s).*' | \ 
     grep -oP '(?<=v)\d+\.\d+\.\d+' 
    register: detected_latest 
    when: version == "latest" 

- name: set detected version 
    set_fact: 
    real_version: "{{ detected_latest.stdout.strip() }}" 
    when: version == "latest" 

- name: set specified verison 
    set_fact: 
    real_version: "{{ version }}" 
    when: version != "latest" 

# set play facts 
- name: set facts 
    set_fact: 
    download_url: "https://github.com/aelsabbahy/goss/releases/download/v{{ real_version }}/goss-linux-amd64" 

# create goss directories 
- name: create goss directories 
    file: path={{ item }} state=directory 
    with_items: 
    - /tmp/degoss 
    - /tmp/degoss/bin 
    - /tmp/degoss/tests 
    notify: clean 

# download goss 
- name: install 
    get_url: 
    url: "{{ download_url }}" 
    dest: /tmp/degoss/bin/goss 
    mode: 0755 

# deploy test cases 
- name: deploy tests 
    copy: src={{ item }} dest=/tmp/degoss/tests/ 
    with_items: "{{ tests }}" 

# run the tests 
- name: run tests 
    goss: executable=/tmp/degoss/bin/goss path="{{ item }}" format="{{ format }}" 
    with_fileglob: /tmp/degoss/tests/*.yml 

、実行されcreate goss directoriesを、それがthe clean handlerトリガー:

--- 
# handlers file for degoss 
- name: clean 
    file: path=/tmp/degoss state=absent 

により、私のモジュールの性質のために、私はいつもからcleanハンドラをしたいですロール内の他のタスクが失敗した場合でも、が実行されます。私の大雑把なテストから、run testsが失敗した場合、ハンドラは決して呼び出されず、一時ファイルはターゲットマシンに残されます。

私の役割のなかで、このハンドラをタスクに何が起こったかに関係なく強制的に実行させる方法はありますか?

答えて

1

Handlers and Failure章を引用:

あなたは、またはansible.cfgで劇中force_handlers: True、またはforce_handlers = Trueを含むことによって--force-handlersコマンドラインオプションを使用してこの動作を変更することができます。ハンドラが強制的に実行されると、そのホスト上でタスクが失敗した場合でも通知されたときに実行されます。 (特定のエラーはまだ、このような到達不能になってきてホストとして、実行されているからハンドラを防ぐことができることに注意してください。)

-1
--- 
    # tasks file for block 
    - name: command 0 
     shell: uname -i 

    - block: 
     - name: command1 
     shell: ls /tmp/ 
     - name: command2 
     shell: ls /tmp/momo 

    rescue: 
    - name: retour arriere ya eu une erreur 
    shell: ls -ls 
+2

レビューキューからの説明、ハンドラと壊れたYAMLインデントとは何の関係も... –

+1

** **あなたの答えの周りにいくつかの文脈を追加してください。コードのみの回答は理解しにくいです。あなたの投稿にさらに情報を追加することができれば、これはAskerと将来の読者に役立ちます。 [コードベースの回答を完全に説明する](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)も参照してください。 –

関連する問題