无聊的IT

导航

1-6 ansible playbook 异常处理

 

#忽略错误 f11
---
- hosts : 144.131.252.252
  remote_user : root
  tasks:
      - name: ignore false
        command: /bin/false
        ignore_errors: yes
      - name: touch a file
        file: path=/tmp/test2 state=touch mode=0700 owner=root group=root

 

 

#failed when 异常 f12

---
- hosts : 144.131.252.252
  remote_user : root
  tasks:
      - name: get process
        shell: ps -ef|wc -l
        register: process_count
        failed_when: "{{process_count.stdout}} < 3"
      - name: touch a file
        #shell: "touch /tmp/a.txt"
        #file: path=/tmp/a.txt state=touch mode=0700 owner=yy1s group=root
        shell: "echo {{process_count.stdout}} >> /tmp/a.txt"

 

 

#changed_when错误 f13
---
- hosts : 144.131.252.252
  remote_user : root
  tasks:
      - name: get process
        shell: touch /tmp/change_test
        changed_when: false

 

posted on 2019-02-13 11:06  秦寒  阅读(484)  评论(0)    收藏  举报