Skip to content

Instantly share code, notes, and snippets.

@TuranTimur
Created August 25, 2024 02:34
Show Gist options
  • Save TuranTimur/a322b806026389178039ddfee01d029d to your computer and use it in GitHub Desktop.
Save TuranTimur/a322b806026389178039ddfee01d029d to your computer and use it in GitHub Desktop.
custom shell by ansible action plugin
# 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