当系统负载超过0.7时,则关掉httpd
ansible]# vim when.yml
---
- hosts: cache
remote_user: root
tasks:
- shell: uptime | awk '{printf("%.2f",$(NF-2))}'
register: result
- service:
name: httpd
state: stopped
when: result.stdout|float < 0.7
(此处写<,方便查看效果)
ansible]# ansible-playbook when.yml