Copy local file if exists, using ansible

Question:

I’m working in a project, and we use ansible to create a deploy a cluster of servers.
One of the tasks that I’ve to implement, is to copy a local file to the remote host, only if that file exists locally.
Now I’m trying to solve this problem using this

Bu this is failing with the following message:
ERROR: ‘action’ or ‘local_action’ attribute missing in task “copy local filetocopy.zip to remote if exists”

I’ve tried to create this if with command task.
I’ve already tried to create this task with a local_action, but I couldn’t make it work.
All samples that I’ve found, doesn’t consider a shell into local_action, there are only samples of command, and neither of them have anything else then a command.
Is there a way to do this task using ansible?

Answer:

Change your first step into the following on

Leave a Reply