Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from ansible.plugins.action import ActionBase
- from ansible.errors import AnsibleFileNotFound
- class ActionModule(ActionBase):
- '''Must have this name for ansible to detect it
- and the name of the file must be the same than the module
- we want to refer'''
- def run(self, tmp=None, task_vars=None):
- module_args = self._task.args # Obtaing module args
- # List of keys in my args that are files
- args_files = ["pfx_file", "pswd_file", "cer_file"]
- for file in args_files:
- try:
- module_args[file] = self._get_absolute_path(module_args[file])
- except AnsibleFileNotFound as e:
- return dict(
- failed=True,
- msg="Couldn't find %s: %s - %s" % (file, module_args[file],
- str(e))
- )
- # Execute module with name pfx_deconstruct with its args modified
- return self._execute_module('pfx_deconstruct', module_args=module_args,
- task_vars=task_vars)
- def _get_absolute_path(self, path):
- if path.startswith('/'):
- return path
- if self._task._role is not None:
- path = self._loader.path_dwim_relative(self._task._role._role_path,
- 'files', path)
- else:
- path = self._loader.path_dwim_relative(self._loader.get_basedir(),
- 'files', path)
- return path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement