Skip to content
Snippets Groups Projects
collect_docker_facts.sh.j2 1.25 KiB
Newer Older
  • Learn to ignore specific revisions
  • Rémi - Le Filament's avatar
    Rémi - Le Filament committed
    #!/bin/bash
    
    # Copyright © 2019 Le Filament (<http://www.le-filament.com>)
    # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
    
    mkdir -p /home/{{ host_user }}/versions
    TODAY=`date +%F`
    
    file="/home/{{ host_user }}/versions/{{ inventory_hostname|lower }}-docker.$TODAY"
    latest_file="/home/{{ host_user }}/versions/{{ inventory_hostname|lower }}-docker.latest"
    printf "DATE = $TODAY"  > $file
    printf "\n\n-- Docker version --\n" >> $file
    /usr/bin/docker version >> $file
    printf "\n\n-- List of containers --\n" >>  $file
    /usr/bin/docker ps -a  >> $file
    printf "\n\n-- List of images --\n" >> $file
    /usr/bin/docker images --digests >> $file
    printf "\n\n-- Disk usage (condensed) --\n" >> $file
    /usr/bin/docker system df >> $file
    printf "\n\n-- Disk usage (full) --\n" >> $file
    /usr/bin/docker system df -v >> $file
    printf "\n\n-- Usage Statistics --\n" >> $file
    /usr/bin/docker stats -a --no-stream >> $file
    cp $file $latest_file
    chmod 644 $file $latest_file
    {% for host in groups.backup_server %}
    
    {% if host != inventory_hostname %}
    
    Rémi - Le Filament's avatar
    Rémi - Le Filament committed
    sftp -P {{ default_sshd_port }} -o IdentityFile=/home/{{ host_user }}/.ssh/id_ed25519 {{ backup_sftp_user }}@{{ hostvars[host].ansible_host }} << COMMANDS
    put $file {{ inventory_hostname|lower }}/
    quit
    COMMANDS
    
    Rémi - Le Filament's avatar
    Rémi - Le Filament committed
    {% endfor %}