oxl-ansible-executor-plugins 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from time import time
|
|
2
|
+
from os import environ
|
|
3
|
+
from sys import stdout
|
|
4
|
+
from json import dumps as json_dumps
|
|
5
|
+
|
|
6
|
+
from ansible.plugins.callback import CallbackBase
|
|
7
|
+
from ansible.executor.task_result import TaskResult
|
|
8
|
+
from ansible.executor.stats import AggregateStats
|
|
9
|
+
|
|
10
|
+
SELECTOR_STATS_RECAP_BEGIN = '__AR_STATS_RECAP_BEGIN__'
|
|
11
|
+
SELECTOR_STATS_RECAP_END = '__AR_STATS_RECAP_END__'
|
|
12
|
+
SELECTOR_STATS_LIVE_BEGIN = '__AR_STATS_LIVE_BEGIN__'
|
|
13
|
+
SELECTOR_STATS_LIVE_END = '__AR_STATS_LIVE_END__'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CallbackModule(CallbackBase):
|
|
17
|
+
CALLBACK_VERSION = 2.0
|
|
18
|
+
CALLBACK_TYPE = 'aggregate'
|
|
19
|
+
CALLBACK_NAME = 'ar_stats'
|
|
20
|
+
CALLBACK_NEEDS_WHITELIST = False
|
|
21
|
+
|
|
22
|
+
def __init__(self):
|
|
23
|
+
super(CallbackModule, self).__init__()
|
|
24
|
+
self.host_stats = {}
|
|
25
|
+
self.last_emit_time = 0
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
self.emit_interval = float(environ.get('AR_STATS_INTERVAL', 10.0))
|
|
29
|
+
|
|
30
|
+
except ValueError:
|
|
31
|
+
self.emit_interval = 10.0
|
|
32
|
+
|
|
33
|
+
def _update_and_maybe_emit(self, host, status):
|
|
34
|
+
if host not in self.host_stats:
|
|
35
|
+
self.host_stats[host] = {
|
|
36
|
+
'ok': 0, 'changed': 0, 'unreachable': 0,
|
|
37
|
+
'failures': 0, 'skipped': 0, 'rescued': 0, 'ignored': 0
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
self.host_stats[host][status] += 1
|
|
41
|
+
|
|
42
|
+
current_time = time()
|
|
43
|
+
if (current_time - self.last_emit_time) >= self.emit_interval:
|
|
44
|
+
self._emit()
|
|
45
|
+
self.last_emit_time = current_time
|
|
46
|
+
|
|
47
|
+
def _emit(self, recap: bool = False):
|
|
48
|
+
payload = json_dumps(self.host_stats)
|
|
49
|
+
|
|
50
|
+
if recap:
|
|
51
|
+
stdout.write("\n" + SELECTOR_STATS_RECAP_BEGIN + payload + SELECTOR_STATS_RECAP_END + "\n")
|
|
52
|
+
|
|
53
|
+
else:
|
|
54
|
+
stdout.write("\n" + SELECTOR_STATS_LIVE_BEGIN + payload + SELECTOR_STATS_LIVE_END + "\n")
|
|
55
|
+
|
|
56
|
+
stdout.flush()
|
|
57
|
+
|
|
58
|
+
def v2_runner_on_ok(self, result: TaskResult):
|
|
59
|
+
if result._result.get('changed', False):
|
|
60
|
+
self._update_and_maybe_emit(result._host.get_name(), 'changed')
|
|
61
|
+
|
|
62
|
+
else:
|
|
63
|
+
self._update_and_maybe_emit(result._host.get_name(), 'ok')
|
|
64
|
+
|
|
65
|
+
def v2_runner_on_failed(self, result: TaskResult, ignore_errors: bool = False):
|
|
66
|
+
if ignore_errors:
|
|
67
|
+
self._update_and_maybe_emit(result._host.get_name(), 'ignored')
|
|
68
|
+
|
|
69
|
+
else:
|
|
70
|
+
self._update_and_maybe_emit(result._host.get_name(), 'failures')
|
|
71
|
+
|
|
72
|
+
def v2_runner_on_skipped(self, result: TaskResult):
|
|
73
|
+
self._update_and_maybe_emit(result._host.get_name(), 'skipped')
|
|
74
|
+
|
|
75
|
+
def v2_runner_on_unreachable(self, result: TaskResult):
|
|
76
|
+
self._update_and_maybe_emit(result._host.get_name(), 'unreachable')
|
|
77
|
+
|
|
78
|
+
def v2_playbook_on_stats(self, stats: AggregateStats):
|
|
79
|
+
for host in stats.processed.keys():
|
|
80
|
+
self.host_stats[host] = stats.summarize(host)
|
|
81
|
+
|
|
82
|
+
self._emit(recap=True)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oxl-ansible-executor-plugins
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Ansible-Plugins for the Simple & Transparent Executor for Ansible-Playbooks
|
|
5
|
+
Author-email: Pascal Rath <rath@oxl.at>
|
|
6
|
+
Project-URL: Homepage, https://github.com/O-X-L/ansible-executor
|
|
7
|
+
Project-URL: Documentation, https://ansible-executor.OXL.app/
|
|
8
|
+
Project-URL: Repository, https://github.com/O-X-L/ansible-executor.git
|
|
9
|
+
Project-URL: Issues, https://github.com/O-X-L/ansible-executor/issues
|
|
10
|
+
Keywords: ansible,executor,runner,automation,iac
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
13
|
+
Classifier: Framework :: Ansible
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: ansible-core
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
oxl_ansible_executor_plugins/callback/ar_stats.py,sha256=lHFLsgZH9Eg_xBaAtwZDKVSCKn-IVDMB7991ro1aWOg,2775
|
|
2
|
+
oxl_ansible_executor_plugins-0.1.dist-info/METADATA,sha256=jmcmk3WBaowPv_t7jj98IwjgJGUtELJ39ZsptDJzUkM,762
|
|
3
|
+
oxl_ansible_executor_plugins-0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
+
oxl_ansible_executor_plugins-0.1.dist-info/top_level.txt,sha256=KYEGEJISUtP2mh0WfrBAESZCdCjuafcDSc0dK2jl6Sk,29
|
|
5
|
+
oxl_ansible_executor_plugins-0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
oxl_ansible_executor_plugins
|