ansible result.stdout.find('running') != -1 判断状态

MySQL服务为running时,停止MySQL服务

复制代码
[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
复制代码

转自

ansible result.stdout.find('running') != -1 判断状态 - 滴滴滴 - 博客园
https://www.cnblogs.com/gaoyuechen/p/7776376.html

 

posted @   paul_hch  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2022-01-04 inotify+rsync双向同步【转】
2021-01-04 nginx_upstream_check_module报错500或403
2020-01-04 Python的property _getter和setter方法【转】
2018-01-04 shell函数中eof报错(warning: here-document at line 9 delimited by end-of-file (wanted `EOF'))
点击右上角即可分享
微信分享提示