Reputation: 3045
I'm using the below ansible-playbook code to archive multiple folders under IBM folder.
Below is my absolute path Directory structure:
/app
|-- /IBM
|--/test
|--/log
|--/common
|--/api
|--/<unknown folders>
The number of folders and files under IBM folder
is unknown hence it seems impossible to specify all the files / folders under IBM under exclude_path
attribute.
I wish to build an archive (gz) that has only IBM folder containing only two folders i.e common
and api
folders while ignoring the rest of the folders and files.
Thus, I wrote the below playbook:
- name: Creating the archive
archive:
path:
- /was/IBM/common
- /was/IBM/api
dest: /var/backup/mysetup.tar.gz
exclude_path:
- /was/IBM/common/log
- /was/IBM/api/tmp
format: gz
This gives me the archive file mysetup.tar.gz
.
I want the mysetup.tar.gz
file to have a folder called IBM which should have the two folders common
and api
. Thus, I'm expecting the below in the mysetup.tar.gz no matter what other files are under the IBM
folder.
IBM
|--/common
|--/api
But, the mysetup.tar.gz does not have IBM
folder but has common
and api
folders.
I was not specific hence my question did not get answered here: How to archive multiple folders under one folder using Ansible
Can you please guide me as to how I can get the archive to have both the folders inside the IBM folder inside the mysetup.tar.gz
?
Upvotes: 0
Views: 1980
Reputation: 3037
Requirement you have can't be achieved straight using archive
module. Two specific reasons are listed below:
path
say /app/IBM
then the content of the zip file will have the path after IBM something like common/
, api/
. To get IBM as a root directory inside the tar.gz file, you need to specify path
as /app
. This brings to the next point about the usage of exclude_path
.exclude_path
doesn't work as you would expect. Say, if the path
is define as /app
and you want to exclude /app/IBM/test
, this wouldn't work. exclude_path
works only with direct sub folder/file of a defined path
(with wildcard) which means that exclusion of /app/IBM/test
would work if path
defined as /app/IBM/*
but that is not what is expected and brings back the previous point. There is already an issue reported on this topic.So you probably better off using regular tar command using command/shell module.
Upvotes: 1