Skip to content
Snippets Groups Projects
Commit 1fc032ca authored by Pietsch, Martin's avatar Pietsch, Martin
Browse files

added action plugin

parent a23a1d2b
No related branches found
No related tags found
No related merge requests found
......@@ -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`
......@@ -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'
......@@ -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>
......
# (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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment