ansible☞playbook-错误捕获

阅读量: zyh 2020-05-04 17:17:44
Categories: > Tags:

前言

类似于 python 中的 try…except…finally,ansible 可以用 block…rescue…always

---
- hosts: localhost
  remote_user: zyh
  gather_facts: no
  tasks:
    - block:
        - shell: mkdir /file
      rescue:
        - debug:
            msg: "No operation permission"
      always:
        - debug:
            msg: "Task End!"

创建 file 目录失败,则输出"No operation permission", 最终总是输出“Task End!”