diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c77d55b5595435d3912b99c935e3d03b8b39ba03..e6bb0f2003c1ab6a966bbe8438e99e65eda888e1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,3 +12,12 @@ Major Changes - added strategy plugins `sdmfree` and `sdmhost_pinned` - added callback plugin `sdmdefault` + +v1.1.0 +====== + +Minor Changes +------------- + +- added action plugin `dump_role_vars` + diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 230e81b2c053dc845810f585f7416aa3acc7b7dc..b0e4d7496324a63749030ae09388a47f55da428a 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -6,3 +6,8 @@ releases: - added strategy plugins `sdmfree` and `sdmhost_pinned` - added callback plugin `sdmdefault` release_date: '2021-03-08' + 1.1.0: + changes: + minor_changes: + - added action plugin `dump_role_vars` + release_date: '2021-06-01' diff --git a/galaxy.yml b/galaxy.yml index a092ae530e8971a6bdfc3ca0d345e8eff6b9c441..f1339cbd7d8c85afbe446d84670ef0d9f6d5c2d6 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -4,9 +4,9 @@ name: oor description: plugins for object oriented roles readme: README.md repository: https://gitlab.mn.tu-dresden.de/sdm/sdm.oor.git -documentation: https://sdm.mn.tu-dresden.de/references/collections/sdm.common/ +documentation: https://sdm.mn.tu-dresden.de/references/collections/sdm.oor/ homepage: https://sdm.mn.tu-dresden.de -version: 1.0.0 +version: 1.1.0 authors: - Martin Pietsch <martin.pietsch@tu-dresden.de> - Robin Richter <robin.richter@mailbox.tu-dresden.de> diff --git a/plugins/action/dump_role_vars.py b/plugins/action/dump_role_vars.py new file mode 100644 index 0000000000000000000000000000000000000000..711ea8cfb1e0446f02701a5a11712cebfc34c487 --- /dev/null +++ b/plugins/action/dump_role_vars.py @@ -0,0 +1,88 @@ +# (c) 2021,Technische Universität Dresden, School of Science, Martin Pietsch <martin.pietsch@tu-dresden.de> +# +# This file is part of SDM Framework +# +# This plugin is free software: You can redistribute this file and/or modify +# file under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# The plugin is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SDM framework. If not, see <http://www.gnu.org/licenses/>. + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION=''' +--- +action: dump_role_vars +short_description: dump variables of the current role +license: GPL-3 license +authors: + - Martin Pietsch (martin.pietsch@tu-dresden.de) +description: + - This module dumps the variables of a role. + - It is part of the object-oriented [role concept](/userguides/sdm/roles/oor) of the SDM framework. +version_added: "2.10" +options: + type: + description: + - Specifies the variable type of the current role which variables should dumped. + type: string + choices: ["vars", "defaults", "all"] + default: "all" +''' + +EXAMPLES=''' +- name: "dump all variables of the current role" + sdm.oor.dump_role_vars: + +- name: "dump default variables of the current role" + sdm.oor.dump_role_vars: + type: "defaults" + +- name: "dump variables of the current role" + sdm.oor.dump_role_vars: + type: "vars" +''' + +from ansible.errors import AnsibleError +from ansible.plugins.action import ActionBase +from ansible.module_utils._text import to_text +from pprint import pformat + +try: + from ansible.plugins.callback.sdmoor import SDMRole, SDMTaskInclude, SDMIncludeRole +except: + from ansible_collections.sdm.oor.plugins.callback.sdmoor import SDMRole, SDMTaskInclude, SDMIncludeRole + +class ActionModule(ActionBase): + + _VALID_ARGS = frozenset(['type']) + + def run(self, tmp=None, task_vars=None): + if self._task._role is None or not isinstance(self._task._role, SDMRole): + raise AnsibleError("This action can only used inside a SDM role!") + + retval = super(ActionModule, self).run(tmp, task_vars) + + varstype = self._task.args.get('type', 'all') + + allvars = dict() + + if varstype == "vars" or varstype == "all": + allvars.update(dict({"vars" : self._task._role._role_vars})) + + if varstype == "defaults" or varstype == "all": + allvars.update(dict({"defaults" : self._task._role._default_vars})) + + retval[to_text(type(allvars))] = allvars + retval['failed'] = False + retval['_ansible_verbose_always'] = True + + return retval