Hi Stewart,
First: including only "copy_release" tag makes ansible skip the first task, as it's tagged only with "copy_files".
Second: you can also use with_filetree<
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/lookup/filetree.py> lookup (introduced in Ansible 2.2) or with_fileglob<
http://docs.ansible.com/ansible/playbooks_loops.html#id4> (if you don't need to iterate a directory recursively).
Then use separate tasks for different actions/extensions with 'when' directive.
This way you'll skip the register task.
Note that these lookups return different data structures for {{ item }}.
fileglob's item is a string containing the file/directory absolute path, while filetree's item is a dict.
Some "documentation" can be found in original pull request<
https://github.com/ansible/ansible/pull/14332>'s description.
When executed as "with_filetree: /tmp", it looks like this for a file (or a link with "state":"link"):
"item": {
"ctime": 1479723235.151,
"gid": 501,
"group": "xxx",
"mode": "0664",
"mtime": 1479723235.151,
"owner": "xxx",
"path": "ansible-debug.log",
"root": "/tmp",
"selevel": "s0",
"serole": "object_r",
"setype": "user_tmp_t",
"seuser": "unconfined_u",
"size": 4104,
"src": "/tmp/ansible-debug.log",
"state": "file",
"uid": 501
}
And like this for a directory (there's no "src"):
"item": {
"ctime": 1479810261.0929983,
"gid": 501,
"group": "xxx",
"mode": "0775",
"mtime": 1479810261.0929983,
"owner": "xxx",
"path": "test",
"root": "/tmp",
"selevel": "s0",
"serole": "object_r",
"setype": "user_tmp_t",
"seuser": "unconfined_u",
"size": 4096,
"state": "directory",
"uid": 501
}
This example copies files only:
- name: Copy files
command: cp {{ item.src }} /tmp/bb/{{ item.path }}
with_filetree: ./demo_deploy
when: item.state == 'file' and item.path.split('/')[0] not in ['ins', 'roles', 'host_vars']
tags:
- copy_release
if you need to preserve the same directory structure, then add this before the task above:
- name: Create directories
file:
dest: /tmp/bb/{{ item.path }}
state: directory
with_filetree: ./demo_deploy
when: item.state == 'directory' and item.path.split('/')[0] not in ['ins', 'roles', 'host_vars']
tags:
- copy_release
Cheers,
Marko
______________________________________________________________________________________________________
CONFIDENTIALITY NOTICE: This message is the property of International Game Technology PLC and/or
its subsidiaries and may contain proprietary, confidential or trade secret information.
This message is intended solely for the use of the addressee. If you are not the intended recipient
and have received this message in error, please delete this message from your system. Any unauthorized
reading, distribution, copying, or other use of this message or its attachments is strictly prohibited.