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
时来天地皆同力,运去英雄不自由