如何将Ansible故障模块与阻止和救援模块一起使用

时间:2019-01-12 23:55:22

标签: ansible

问题:当条件满足我的条件时,我的游戏失败:(-名称:当条件满足时我的游戏失败:A = NULL),失败后我的救援就没有运行。我要在这里实现的一切是:失败播放并设置事实并发送通知

-任务:    -名称:区块从这里开始    -块:        -名称:第1步          命令:        -名称:条件满足时我的游戏失败:A = NULL    -名称:救援从这里开始      拯救:         -名称:set_fact           set_fact:              结果:“ {%if('A = NULL')%}失败{%endif%}”

    - name: Send notification message via Slack
      slack:
       domain: slack.com
       token: value
       username: UserA
       msg: 'Here is my result {{ Result }}'
       validate_certs: no

1 个答案:

答案 0 :(得分:0)

问题中的格式似乎已损坏,因此不清楚您到底尝试了什么。试试这个:

 - block:
     - name: Fail play if A not set
       fail:
         msg: "A is null"
       when: A is null
   rescue:
     - name: Set failure status variable
       set_fact:
         Result: Failure
     - name: Send notification message via Slack
       slack:
         domain: slack.com
         token: value
         username: UserA
         msg: "Here is my result {{ Result }}"
         validate_certs: no