We need to be able to copy/push multiple files from multiple sources to multiple destinations on destination servers, I’m having trouble with below code, can anyone suggest the right syntax to update code?
I have 3 different files and destination is different for all of them and need this across my inventory, from a syntax standpoint I do not have any issues however, it does not push those files to destination servers.
First I need to check if the directory exists or NOT & create it, works perfect!!
Second: After the above directory is created, I need to copy 3 different files from 3 different sources to 2 destinations. In other words many to many copy is NOT working for me.
Depending if you want to copy to linux machine or windows so then there are also different modules to use in order to copy bunch of files from the same location source.
This is a 100% linux/unix environment, so I did not even consider win_copy, do you think “win_copy” will work on/for “linux to linux” ? I will definitely give it a try & also need permissions intact at destination, so I would need to insert mode for those files.
You may use below code to perform many to many copy. You may use a when condition to ensure that copy task takes place only when the directory is sucessfully created. In case of directory creation getting failed, the
copy task would not be performed.
Below is the detailed playbook:
create the directory
check if maven repo directory exists on destination server
copy files from source to destination once the creation is successful
You cannot implement this scenario using Notify-Handler. You will have to use the WHEN condition (Implementation shown in below playbook).
One of the property of Handlers is that they get fired only if there is a change in state of the task which is triggering the notification (Notify Statement).
In your use-case there are 2 scenarios:
Scenario-1: The destination maven repo does not exist and is created by the File module. In this case there is a change in state of task which triggers the Notification to “maven repo created” handler. Hence the handler will execute and the files would get copied.
Scenario-2: The destination maven repo already exists and File module does nothing that results in the change of state of the task. Hence when the notification reaches the Handler it does nothing and files are not copied.
Since this is a valid effect produced by the Handler hence there were no error/alerts thrown during the playbook execution.