Files
ansible-playbooks/mattgpt-capture.yaml
2025-11-28 17:26:03 -08:00

101 lines
3.0 KiB
YAML

---
# https://www.youtube.com/watch?v=GuTcle5edjk
- name: Mattgpt Container Capture
hosts: all
become: yes
vars:
remote_mount_folder: "/opt/cosmos/mattgpt_temp"
remote_smb_path: "//172.20.25.10/terra/mattgpt"
local_archive_path: "/opt/cosmos/archives"
mattgpt_docker_path: "/opt/docker/40-mattgpt"
###############################################
# Playbook to capture mattgpt docker data
###############################################
tasks:
###############################################
# Mount remote archive folder
###############################################
- name: MattGPT Capture - Remote Archive Path Check
file:
path: "{{ remote_mount_folder }}"
state: directory
owner: root
group: root
mode: '0755'
- name: MattGPT Capture - Local Archive Folder Check
file:
path: "{{ local_archive_path }}"
state: directory
owner: root
group: root
mode: '0755'
- name: MattGPT Capture - Mount network share
mount:
path: "{{ remote_mount_folder }}"
src: "{{ remote_smb_path }}"
fstype: cifs
opts: "username=behemoth,password={{ saturn_behemoth }}"
state: mounted
###############################################
# Archive mattgpt folder
###############################################
- name: MattGPT Capture - Stop Container
shell: "docker stop mattgpt"
- name: MattGPT Capture - Create Archive Tarball
shell: "tar --use-compress-program=pigz -cf {{ local_archive_path }}/mattgpt.tar.gz -C {{ mattgpt_docker_path }} ."
- name: MattGPT Capture - Get Relavent Sizes
shell: |
du -sh {{ mattgpt_docker_path }} | cut -d '/' -f 1,4 | awk '{print $2 ": " $1}'
ls -lah {{ local_archive_path }} | grep tar | awk '{print $9 ": " $5}'
register: archive_size_output
- name: MattGPT Capture - Show Archive Sizes
debug:
msg: "{{ archive_size_output.stdout_lines }}"
- name: MattGPT Capture - Start Container
shell: "docker start mattgpt"
###############################################
# Copy archive to network and remove local copy
###############################################
- name: MattGPT Capture - Copy archives
shell: "cp {{ local_archive_path }}/mattgpt.tar.gz {{ remote_mount_folder }}/mattgpt.tar.gz"
- name: MattGPT Capture - Delete local files
shell: "rm {{ local_archive_path }}/mattgpt.tar.gz"
###############################################
# Unmount network share
###############################################
- name: MattGPT Capture - Unmount network share
mount:
path: "{{ remote_mount_folder }}/"
state: absent
- name: MattGPT Capture - Make sure mountpoint is gone from fstab
lineinfile:
path: /etc/fstab
regexp: "{{ remote_mount_folder }}"
state: absent
- name: MattGPT Capture - Manually Unmount Share
shell: "umount {{ remote_mount_folder }}"
...