-
Notifications
You must be signed in to change notification settings - Fork 19
/
service.yml
123 lines (106 loc) · 4.5 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
# linux_postinstall service
- name: "Service: Debug lp_service_debug={{ lp_service_debug }}"
when: lp_service_debug | bool
tags: lp_service_debug
vars:
msg: |-
ansible_os_family: {{ ansible_os_family }}
ansible_service_mgr: {{ ansible_service_mgr }}
lp_service_sanity: {{ lp_service_sanity }}
lp_service_module: {{ lp_service_module }}
lp_service_module_valid: {{ lp_service_module_valid }}
lp_service:
{{ lp_service | to_nice_yaml(indent=2) | indent(2) }}
lp_service_auto:
{{ lp_service_auto | to_nice_yaml(indent=2) | indent(2) }}
ansible.builtin.debug:
msg: "{{ '{}'.format(msg) }}"
- name: Sanity
when: lp_service_sanity | bool
tags: lp_service_sanity
block:
- name: "Service: Get service facts"
ansible.builtin.service_facts:
- name: "Service: Debug my_services_* lp_service_debug2={{ lp_service_debug2 }}"
when: lp_service_debug2 | d(false) | bool
vars:
my_services_alias: "{{ lp_service_auto }}"
msg: |-
my_services_regex: {{ my_services_regex }}
my_services_all: {{ my_services_all | to_yaml }}
my_services_varnames:
{{ my_services_varnames | to_nice_yaml(indent=2) | indent(2) }}
my_services_names:
{{ my_services_names | to_nice_yaml(indent=2) | indent(2) }}
my_services_undef:
{{ my_services_undef | to_nice_yaml(indent=2) | indent(2) }}
ansible.builtin.debug:
msg: "{{ '{}'.format(msg) }}"
- name: "Service: Sanity lp_service_auto items are defined"
when: lp_service_auto | length > 0
vars:
my_services_alias: "{{ lp_service_auto }}"
ansible.builtin.assert:
that: my_services_undef | length == 0
fail_msg: "[ERR] Undefined services: {{ my_services_undef }}"
success_msg: "[OK] All service names in lp_service_auto are valid."
quiet: "{{ lp_service_sanity_quiet }}"
- name: "Service: Sanity lp_service names are defined"
when: lp_service | length > 0
vars:
my_services_alias: "{{ lp_service | map(attribute='name') }}"
ansible.builtin.assert:
that: my_services_undef | length == 0
fail_msg: "[ERR] Undefined services: {{ my_services_undef }}"
success_msg: "[OK] All service names in lp_service are valid."
quiet: "{{ lp_service_sanity_quiet }}"
- name: "Service: Sanity lp_service_module"
ansible.builtin.assert:
that: lp_service_module in lp_service_module_valid
fail_msg: "[ERR] {{ lp_service_module }} not in {{ lp_service_module_valid }}"
success_msg: "[OK] {{ lp_service_module }} is valid value of lp_service_module."
quiet: "{{ lp_service_sanity_quiet }}"
- name: Automatic management of services
when: lp_service_auto | length > 0
tags: lp_service_auto
block:
- name: "Service: Automatic management of services"
when: run_task | bool
register: result
notify: reload {{ ansible_service_mgr }} daemon
vars:
my_services_alias: "{{ lp_service_auto }}"
vbase: "{{ item | reverse | replace('ecivres_', '', 1) | reverse }}"
run_task: "{{ lookup('vars', vbase, default=false) }}"
srv_name: "{{ lookup('vars', vbase ~ '_service', default=item) }}"
srv_enbl: "{{ lookup('vars', vbase ~ '_enable', default=false) }}"
use_modl: "{{ lookup('vars', vbase ~ '_module', default='auto') }}"
srv_stat: "{{ lookup('vars', vbase ~ '_state', default=default_state) }}"
default_state: "{{ srv_enbl | bool | ternary('started', 'stopped') }}"
ansible.builtin.service:
name: "{{ srv_name }}"
state: "{{ srv_stat }}"
enabled: "{{ srv_enbl | bool }}"
use: "{{ use_modl }}"
loop: "{{ my_services_varnames }}"
loop_control:
label: "{{ srv_name }} enabled={{ srv_enbl }} state={{ srv_stat }} use={{ use_modl }}"
- name: "Service: Debug"
ansible.builtin.include_tasks: fn/service-debug.yml
- name: Manual management of services
when: lp_service | length > 0
tags: lp_service_manual
block:
- name: "Service: Manual management set module auto"
when: lp_service_module == 'auto'
ansible.builtin.set_fact:
lp_service_module: "{{ ansible_service_mgr }}"
- name: "Service: Include {{ lp_service_module }}"
ansible.builtin.include_tasks: fn/service-{{ lp_service_module }}.yml
- name: "Service: Flush handlers"
tags:
- lp_service_auto
- lp_service_manual
ansible.builtin.meta: flush_handlers
# EOF