From 852d425d25704c767540125849f28b899d9a382e Mon Sep 17 00:00:00 2001 From: Mauro Torrez Date: Fri, 2 Oct 2020 17:58:28 -0300 Subject: [PATCH] initial commit: start from basic action plugin --- .gitignore | 6 ++++++ wildfly.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .gitignore create mode 100644 wildfly.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c24c661 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*~ +\#* +.#* +*.pyc +*.bak +__pycache__ diff --git a/wildfly.py b/wildfly.py new file mode 100644 index 0000000..a5390e1 --- /dev/null +++ b/wildfly.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +# Make coding more python3-ish, this is required for contributions to Ansible +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action import ActionBase +from datetime import datetime + + +class ActionModule(ActionBase): + def run(self, tmp=None, task_vars=None): + super(ActionModule, self).run(tmp, task_vars) + module_args = self._task.args.copy() + module_return = self._execute_module(module_name='setup', + module_args=module_args, + task_vars=task_vars, tmp=tmp) + ret = dict() + remote_date = None + if not module_return.get('failed'): + for key, value in module_return['ansible_facts'].items(): + if key == 'ansible_date_time': + remote_date = value['iso8601'] + + if remote_date: + remote_date_obj = datetime.strptime(remote_date, '%Y-%m-%dT%H:%M:%SZ') + time_delta = datetime.now() - remote_date_obj + ret['delta_seconds'] = time_delta.seconds + ret['delta_days'] = time_delta.days + ret['delta_microseconds'] = time_delta.microseconds + + return dict(ansible_facts=dict(ret))