OS Environment
CentOS Linux release 7.3.1611 (Core)
Ansible Version
ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
使用情境說明
先去抓所有的tar檔後,註冊一個變數
AllTarFileName
,再echo需要排除的檔名,並且也把它註冊成一個變數TarName,之後就可以在解tar檔時,使用差集
的方式,將不需要的檔案做排除。task.yml
- name: Get All Tar Files Name
shell: az storage blob list -o table -c {{ BLOB_CONTAINER }} --account-name {{ BACKUP_ACCOUNT }} --account-key {{ BACKUP_KEY }} | grep -Eo '{{RestoreBuildNumber.content}}.tar.gz|{{ RestoreBuildNumber.content }}/*/.*.gz' | cut -d'/' -f3
register: AllTarFileName
- name: Get {{RestoreBuildNumber.content}}.tar.gz Name
shell: echo '{{ RestoreBuildNumber.content }}.tar.gz'
register: TarName
- name: Unarchive {{RestoreBuildNumber.content}}.tar.gz To /tmp/{{RestoreBuildNumber.content}}/data/
shell: tar -zxvf /tmp/{{RestoreBuildNumber.content}}/{{item}} -C /tmp/{{RestoreBuildNumber.content}}/data/
with_items:
- "{{TarName.stdout_lines }}"
- name: Unarchive All Archives Tar Files
shell: tar -zxvf /tmp/{{RestoreBuildNumber.content}}/{{item}} -C /tmp/{{RestoreBuildNumber.content}}/backups/
with_items:
- "{{ AllTarFileName.stdout_lines | difference(TarName.stdout_lines) }}"
Reference:
感謝 Ansible Taiwan - Jim T. Tang 大大的建議。
沒有留言:
張貼留言