Hello,
I am trying to create my own action plugin. Here it is :
myAction.py:
from ansible.plugins.action import ActionBase
class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
super(ActionModule, self).run(tmp, task_vars)
# print(f"tmp = {tmp}, task_vars = {task_vars}")
module_args = self._task.args.copy()
print(f"module_args = {module_args}")
module_return = self._execute_module(module_name='copy',
module_args=module_args,
task_vars=task_vars, tmp=tmp)
print(f"module_return = {module_return}")
ret = dict()
return dict(ansible_facts=dict(ret))
As you may see, it only tries to execute the copy module.
Here is the invocation:
myaction.yml:
- name: test copy file
copy:
src: foo.txt
dest: /etc/foo2.txt
- name: test
myAction:
src: foo.txt
dest: /etc/foo.txt
remote_src: no
As you can see I am invoking first the normal copy module. Which works fine since I find the /etc/foo2.txt file on the remote machine. In second step I invoke myAction (the action plugin) which does not work as it returns a failure, and the /etc/foo.txt file is not created on the remote machine. Here is the result on the standard output:
TASK [myaction : test] ************************************************************************************************************************************************************************************
module_args = {'src': 'foo.txt', 'dest': '/etc/foo.txt', 'remote_src': False}
module_return = {'failed': True, 'msg': 'Source foo.txt not found', 'invocation': {'module_args': {'src': 'foo.txt', 'dest': '/etc/foo.txt', 'remote_src': False, 'backup': False, 'force': True, 'follow': False, 'unsafe_writes': False, '_original_basename': None, 'content': None, 'validate': None, 'directory_mode': None, 'local_follow': None, 'checksum': None, 'mode': None, 'owner': None, 'group': None, 'seuser': None, 'serole': None, 'selevel': None, 'setype': None, 'attributes': None}}, '_ansible_parsed': True}
As you can see the message is ‘Source foo.txt not found’. I’ve tried to specify an absolute path, it does not work either. I specify ‘remote_src: no’ as well in the invokation of myAction.
Is someone able to tell me why the copy module is not able to find my foo.txt file in the second case (when invoked from my action plugin)?
Regards
Yves