如何使用 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屋!