How to archive multiple folders under one folder using Ansible

醉酒当歌 提交于 2021-01-29 05:16:08

问题


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

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

This gives me the file 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

But, the mysetup.tar.gz has no IBM folder but only the common and api folders.

Can you please guide me as to how I can get the archive to have both the folders inside the IBM folder?


回答1:


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


来源:https://stackoverflow.com/questions/62850333/how-to-archive-multiple-folders-under-one-folder-using-ansible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!