oxl-ansible-executor-plugins 0.1__tar.gz

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,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 @@
1
+ 0.1
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "oxl-ansible-executor-plugins"
7
+ authors = [
8
+ {name = "Pascal Rath", email = "rath@oxl.at"},
9
+ ]
10
+ description = "Ansible-Plugins for the Simple & Transparent Executor for Ansible-Playbooks"
11
+ readme = "README.md"
12
+ requires-python = ">=3.11"
13
+ keywords = ["ansible", "executor", "runner", "automation", "iac"]
14
+ license = {file = "LICENSE.txt"}
15
+ classifiers = [
16
+ 'Programming Language :: Python :: 3',
17
+ 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
18
+ 'Framework :: Ansible',
19
+ ]
20
+ dynamic = ["dependencies", "version"]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/O-X-L/ansible-executor"
24
+ Documentation = "https://ansible-executor.OXL.app/"
25
+ Repository = "https://github.com/O-X-L/ansible-executor.git"
26
+ Issues = "https://github.com/O-X-L/ansible-executor/issues"
27
+
28
+ [tool.setuptools.dynamic]
29
+ dependencies = {file = ["requirements.txt"]}
30
+ version = {file = ["VERSION"]}
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
34
+ include = ["oxl_ansible_executor_plugins", "oxl_ansible_executor_plugins.*"]
35
+
36
+ [tool.setuptools.package-data]
37
+ "*" = []
@@ -0,0 +1 @@
1
+ ansible-core
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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,14 @@
1
+ VERSION
2
+ pyproject.toml
3
+ requirements.txt
4
+ ../src/oxl_ansible_executor_plugins.egg-info/PKG-INFO
5
+ ../src/oxl_ansible_executor_plugins.egg-info/SOURCES.txt
6
+ ../src/oxl_ansible_executor_plugins.egg-info/dependency_links.txt
7
+ ../src/oxl_ansible_executor_plugins.egg-info/requires.txt
8
+ ../src/oxl_ansible_executor_plugins.egg-info/top_level.txt
9
+ src/oxl_ansible_executor_plugins.egg-info/PKG-INFO
10
+ src/oxl_ansible_executor_plugins.egg-info/SOURCES.txt
11
+ src/oxl_ansible_executor_plugins.egg-info/dependency_links.txt
12
+ src/oxl_ansible_executor_plugins.egg-info/requires.txt
13
+ src/oxl_ansible_executor_plugins.egg-info/top_level.txt
14
+ src/oxl_ansible_executor_plugins/callback/ar_stats.py