Dev
(Dev)
November 9, 2017, 7:54am
1
Hello everyone,
I have the following structure:
dir1
├── a1
│ └── one.jar
├── a2
│ └── target
│ └── two.jar
├── a3
│ └── subdir
│ └── target
│ ├── three.jar
│ ├── four.jar
│ ├── five.jar
│ └── six.war
└── a4
└── target
└── tmp
└── seven.jar
And I want to copy all *.jar files just under target directory to single remote directory. So the remote location should include files: two, three, four and five (except one, six and seven). I tried to use with_fileglob and with_filetree but without success. Can you help me?
`
name: Copy
copy:
src: “{{ item }}”
dest: ~/dir2
with_filetree: ~/dir1/…/target/*.jar
`
with_filetree doesn't support wildcard and with_fileglobe doesn't support recursive.
If would like to copy all the files recursive in a directory you can use this
- name: Copy
copy:
src: "{{ item.src }}"
dest: ~/dir2/{{ item.src.split('/') | last }}
with_filetree: ~/dir1//target/
If not you would need to use find module and then copy the files with the copy module.
Dev
(Dev)
November 13, 2017, 7:40am
3
Thanks for suggestion. I already did what I wanted using the following:
`
name: Copy
copy:
src: “{{ item.src }}”
dest: ~/dir2
with_filetree: ~/dir1/
when:
item.state == “file”
item.path.split(‘/’)[-2] == “target”
item.path.split(‘.’) | last == “jar”
`
W dniu czwartek, 9 listopada 2017 08:54:38 UTC+1 użytkownik Dev napisał: