This documentation explains how to copy files and directories using the copy
module in Ansible. How to copy all childs except one?
Discussion
- The options do not clarify how it could be done.
- Copying all childs individually is not an option as the parent contains more than 100 childs.
Best option would probably to use the
synchronize
module.Whereas the
copy
module copies files using Python and is limited in its functionality. There is a Note in the copy module documentation:With the
synchronize
module it is possible to passexclude
patterns viarsync_opts
to thersync
command being executed by Ansible.But the
synchronize
module has some caveats. Like the the requirement ofrsync
installed on local and remote machine. That's why I wouldn't use it when not needed.If I had to use just
copy
, here is what I would do. In this example I am usingpatterns
that are specific to Python and a.hiddenfile
(I'm using hidden to demonstrate find has a lot of options to explore). However the basic idea - you can go wild with patterns/regex filters to meet your needs.