Wrapping action_plugins in an action_plugin

Hi,

I am writing an action_plugin that gets a list of files to transfer, their mode and if they are a template.

The action_plugin shall check the template flag (boolean) and depending on its value either

  • (false) run the copy action_plugin (and hence the copy module) with parameters
  • (true) run the template action_plugin (and hence the copy module) with parameters
    After digging into the Ansible source code, I came up with the following solution: https://gist.github.com/6478f921d94423be92ac.git

However, this approach only works for the first item to be transferred, as you can see in the console output in the gist.
After the first run of the plugin (no matter which one), the transferred modules are deleted by some code in Ansible, I think it is the code of the action_plugins I am calling.
In the example, the file module has been deleted on the remote host which is required by the template module.

Do you see any way to stop the plugins from deleting transferred modules?
Or do you have an alternative idea on how I could approach my problem?

(I need to execute Python code to gather the list of transfers, hence, I will need to write an action_plugin. So: I appreciate tips on how to do this in a playbook but this is not what I am looking for).

Thanks,

Chris