ansible 条件语句when

当ansible_os_family为RedHat时,执行/bin/ps -ef >>/tmp/ps


[root@node110 yml]# cat when.yml 
---
- hosts: 192.168.198.120
  tasks:
    - name: "ps -ef when os is redhat " 
      shell: /bin/ps -ef >>/tmp/ps
      when: ansible_os_family == "RedHat"


模型:
tasks:
- command: /bin/false
 register: result
   ignore_errors: True
- command: /bin/something
 when: result|failed #当result执行的结果为failed时,执行/bin/something
- command: /bin/something_else
 when: result|success #当result的执行结果为success时,执行/bin/something_else
- command: /bin/still/something_else
 when: result|skipped







分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS