如何使用Ansible将一个文件夹下的多个文件夹归档 [英] How to archive multiple folders under one folder using Ansible
问题描述
我正在使用下面的ansible-playbook代码将多个文件夹归档到IBM文件夹下.
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
我希望构建一个仅具有IBM文件夹的归档文件(gz),该文件夹仅包含 common
和 api
文件夹.
I wish to build an archive (gz) that has only IBM folder containing only common
and api
folders.
因此,我写了以下剧本:
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/log
- /was/IBM/test
format: gz
这给了我文件 mysetup.tar.gz
.
我希望 mysetup.tar.gz
文件具有一个名为IBM的文件夹,该文件夹应具有common和api两个文件夹.因此,我期望在 mysetup.tar.gz
I want the mysetup.tar.gz
file to have a folder called IBM which should have two folders common and api. Thus, I'm expecting the below in the mysetup.tar.gz
IBM
|--/common
|--/api
但是, mysetup.tar.gz
没有IBM文件夹,只有 common
和 api
文件夹.
But, the mysetup.tar.gz
has no IBM folder but only the common
and api
folders.
您能指导我如何使归档文件将两个文件夹都包含在IBM文件夹中吗?
Can you please guide me as to how I can get the archive to have both the folders inside the IBM folder?
推荐答案
您需要包括整个IBM文件夹,然后排除不需要的路径
You need to include whole IBM folder and then exclude paths you do not want
- name: Creating the archive
archive:
path:
- /was/IBM
dest: /var/backup/mysetup.tar.gz
exclude_path:
- /was/IBM/log
- /was/IBM/test
format: gz
这篇关于如何使用Ansible将一个文件夹下的多个文件夹归档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!