- fail: msg="Bailing out. this play requires 'bar'"
when: bar is not defined
我的需求是当某一个任务执行失败时,应该中断后面的任务,而不是跳过。这个需要结合fail模块来实现了。
我们将/tmp/test.sh脚本输出改回"failed"。删除/tmp下的fstab文件。修改register.yml文件
--- - hosts: test remote_user: root
tasks:
- command : /tmp/test .sh
register: result
- name: if stdout chekck failed,interrupt execution
fail: msg= "check failed"
when: result.stdout == "failed"
- file : path= /tmp/test owner=root group=root mode=0755 state=directory
- copy: src= /etc/fstab dest= /tmp/fstab owner=root group=root mode=0644
|