如何在ansible中控制救援模块的执行

时间:2017-09-17 15:54:23

标签: ansible

我有一个如下所示的剧本,我想控制块出错时执行救援。 我在救援后添加when: is_debug is defined,但是当我运行ansible-playbook dashboard.yml时,不提供is_debug值,当阻止错误时,救援仍然是执行。

我想知道如何控制ansible中救援模块的执行情况?

[root@ansiable-test update]# cat dashboard.yml
---
- hosts: controller
  vars_files:
        - "vars/vars.yml"
  tasks:
    - name: update horizon
    - block:
        - include: "roles/dashboard/tasks/update-horizon.yml"
      rescue:
      when: is_debug is defined
        - debug: msg='An error occurred during the upgrade,roll back to the old version'
        - include: "roles/dashboard/tasks/rollback.yml"

1 个答案:

答案 0 :(得分:3)

没有block"模块"。它是when语法的一部分,您不能仅将rescue应用于when部分。您可以将rescue条件应用于- hosts: controller vars_files: - "vars/vars.yml" tasks: - name: update horizon - block: - include: "roles/dashboard/tasks/update-horizon.yml" rescue: - debug: msg='An error occurred during the upgrade,roll back to the old version' when: is_debug is defined - include: "roles/dashboard/tasks/rollback.yml" when: is_debug is defined 节中的任务(或任务):

var database = firebase.database(); // I add this line

$('.fruit').click(function(){
    var name = $(this).text();
    getFuitName(name);
});

function getFruitName(name){
    var fruit = database.ref('fruit/' + name ); //and then modified this line
    fruit.once('value', function(snapshot) {
        console.log(snapshot.val().name);
    });
}