Hi Brian,
thanks for asking.
So this is a custom python module, It’s for a very domain specific process, I wont go into the exact steps.
But it needs to use bunch of file during the process. the file part is very similar to the copy or template module which is copy the files from control to remotes and the file needs to be updated few times during the process.
I had a look at AnsibleModule api, there is a atomic_move, which is what copy module uses, but after some digging, i realized the atomic_move is only moving from local to local, and for copy module, the src file/s has been zipped up with copy.py and sent over to remote before copy.py is called by ansible on remote. Which make complete sense, the modules are only executing on remotes, the files they use must be made available to them by ansible framework before they are invoked.
This is exactly what i need to do, i need to get the files required to be send over to remote in same zip with my custom_module.py. It must be a very simple config/api, but I just can’t find it.
I did come cross _transfer_file from normal action ActionBase, looks like action is where it happens, but developing an custom actions seem to be an overkill for such a common user case, and i dont want to reinvent wheels. I am hopping there must be a public version of this _transfer_file api, but i couldn’t find it. And think about it again,
I hope that give you a better pic.
And yes, I am using copy module to get files over for now, it’s working, but i consider it as a work around, because it’s exposing a file which is completely internal, and i have to do lots of boil plate on owner/group, permission, encryption, creating temp folder, deleting tmp, etc. Further more, these files should be completely hidden by whoever is using/maintaining the playbook.
And yes, i understand the merits of using copy module or template module, if you think i should be sticking to them, please consider this as a purely technical question, which is how to use ansible python API to send files to remote for a custom module.