diff --git a/templates/collect_installed_packages_facts_Debian.sh.j2 b/templates/collect_installed_packages_facts_Debian.sh.j2 index b01f3a156b6cd5c337373672d64b1581f8c90b3f..ba0592af346a9641962ebd452bae2ac0529e746e 100644 --- a/templates/collect_installed_packages_facts_Debian.sh.j2 +++ b/templates/collect_installed_packages_facts_Debian.sh.j2 @@ -3,30 +3,34 @@ # 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 }}.$TODAY" -latest_file="/home/{{ host_user }}/versions/{{ inventory_hostname|lower }}.latest" -printf "DATE = $TODAY" > $file -printf "\n\n-- OS version --\n" >> $file -lsb_release -a >> $file -printf "\n\n-- Installed OS packages --\n" >> $file -apt list --installed >> $file -if [[ -f "/usr/bin/pip" ]]; then - printf "\n\n-- Installed Python packages --\n" >> $file - pip list installed >> $file -fi -if [[ -f "/usr/bin/pip3" ]]; then - printf "\n\n-- Installed Python 3 packages --\n" >> $file - pip3 list installed >> $file -fi -cp $file $latest_file -chmod 644 $file $latest_file + +VERSIONS_DIR='/home/{{ host_user }}/versions' + +today=$(date '+%F') +outfile_apt="${VERSIONS_DIR}/apt_{{ inventory_hostname|lower }}.${today}" +outfile_apt_hr="${VERSIONS_DIR}/apt-hr_{{ inventory_hostname|lower }}.${today}" +outfile_pip3="${VERSIONS_DIR}/pip3_{{ inventory_hostname|lower }}.${today}" +outfile_pip3_hr="${VERSIONS_DIR}/pip3-hr_{{ inventory_hostname|lower }}.${today}" + +mkdir --parents "${VERSIONS_DIR}" + +dpkg-query --no-pager --show --showformat '${Package}|${Version}|${Architecture}|${db:Status-Abbrev}\n' | paste -s -d ';' > $outfile_apt +apt-mark showmanual | paste -s -d ';' >> $outfile_apt + +python3 -m pip list --pre --format json > $outfile_pip3 +python3 -m pip list --pre --not-required --format json >> $outfile_pip3 + +apt list --installed > $outfile_apt_hr + +pip3 list installed > $outfile_pip3_hr + {% for host in groups.backup_server %} {% if host != inventory_hostname %} -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 }}/ +sftp -b - -P {{ default_sshd_port }} -o IdentityFile=/home/{{ host_user }}/.ssh/id_ed25519 {{ backup_sftp_user }}@{{ hostvars[host].ansible_host }} << COMMANDS +-put ${outfile_apt} {{ inventory_hostname|lower }}/ +-put ${outfile_pip3} {{ inventory_hostname|lower }}/ +-put ${outfile_apt_hr} {{ inventory_hostname|lower }}/ +-put ${outfile_pip3_hr} {{ inventory_hostname|lower }}/ quit COMMANDS {% endif %}