For some weird reasons I'm having troubles with a simple task which is copying a content of the folder myfiles
(few files in there) to the dist/myfiles
location. Task looks like this:
name: Deploy config files like there is no tomorrow
copy:
src: "{{ item }}"
dest: "/home/{{ ansible_user_id }}/dist/{{ item }}"
with_items:
- 'config'
- 'myfiles/'
myfiles
folder exist under the dist
and config
file is copied to the dist
folder.
Is this possible in Ansible or I should copy each file separately? Am I doing it completely wrong?
Your task copies both: the
config
file and themyfiles
on Debian and CentOS targets properly.If for some reason you have a problem, you might have a look at Looping over Fileglobs.
You need to split the task into two, with the second one looking like:
For a recursive copy, check this question on SeverFault
Alternatively, you could use the
synchronize
module, but pay special attention when usingbecome
. See this question on SuperUser.