forked from xcloudlive/ansible-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_service.yml
45 lines (42 loc) · 1.25 KB
/
check_service.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
- name: loop to check service status
hosts: all
gather_facts: no
vars:
service_list:
- name: netconsole
status: running
- name: firewalld.service
status: running
result: ok
tasks:
- name: Gathering service facts
service_facts:
register: services_state
- name: print all of service status
debug: var=services_state.ansible_facts.services
- name: loop for get detail of service
block:
- assert:
that:
- item.name in services
- services[item.name].state == item.status
fail_msg: "{{ item.name }} is not in status {{ item.status }}"
msg: "{{ item.name }} is in status {{ item.status }}"
vars:
services: "{{ services_state.ansible_facts.services }}"
# ignore_errors: true
with_items: "{{ service_list }}"
rescue:
- set_fact:
result: failed
- fail:
msg: error is happened
when: result == "failed"
- name:
debug:
msg: 'I also never execute :-('
always:
- name: always to check result
debug:
msg: "all tasks are finished, result is {{ result }}"