當系統負載超過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