Created
August 25, 2024 02:34
-
-
Save TuranTimur/a322b806026389178039ddfee01d029d to your computer and use it in GitHub Desktop.
custom shell by ansible action plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# roles/myrole/action_plugins/myshell.py | |
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_args['_raw_params'] = module_args.get('cmd') | |
module_args['_uses_shell'] = True | |
module_args.pop('cmd', None) | |
# put your logics here... | |
result = self._execute_module(module_name='command', | |
module_args=module_args, | |
task_vars=task_vars, tmp=tmp) | |
# put your logics also here... | |
return result | |
# roles/myrole/tasks/main.yml | |
--- | |
- myshell: | |
cmd : "echo 123 > /root/test.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment