ansible result.stdout.find('running') != -1 判斷狀態


[root@m01 ansible-playbook]# cat test_1103.yml
---
- hosts: webserver
  tasks:
    - file: path=/tmp/{{ item }} state=touch
      with_items:
        - a.txt
        - b.txt
- hosts: db01
  tasks:
    - shell: /etc/init.d/mysqld status
      register: result
#    - shell: echo "{{ result.stdout }}" >>/tmp/aa.txt
    - service: name=mysqld state=stopped
      when: result.stdout.find('running') != -1

 

[root@db01 ~]# /etc/init.d/mysqld status
 SUCCESS! MySQL running (1356)
[root@db01 ~]# /etc/init.d/mysqld status
 ERROR! MySQL is not running


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM