I am trying to write a playbook which shows failed when number of process running in linux host is not equal to 2. Following playbook works, but is there any better way of doing it? like is there any specific Ansible module to check process linux host?
---
- hosts: web
become: yes
become_method: su
become_user: webuser
tasks:
- name: process check
shell: ps -ef|grep -i etas|grep -v grep|wc -l
register: command_result
failed_when: "'2' not in command_result.stdout"
What is your Ansible version? There is no Ansible module to count the number of processes in Linux. You can make it readable by:
tasks:
- name: process check
shell: pgrep etas | wc -l
register: command_result
failed_when: command_result.stdout|int != 2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.