From 80a40df6c4b66f4565792172cd0c503aca5b1a40 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 13 Jul 2021 21:43:14 +0200 Subject: [PATCH] [proxmox] Automatically synchronize Debian images Signed-off-by: Yohann D'ANELLO --- group_vars/virtu.yml | 4 ++++ host_vars/gulp.cachan-adm.crans.org.yml | 3 +++ plays/proxmox.yml | 8 ++++++++ plays/root.yml | 1 + roles/proxmox-debian-images/tasks/main.yml | 18 ++++++++++++++++++ .../templates/cron.d/debian-images.j2 | 3 +++ 6 files changed, 37 insertions(+) create mode 100644 group_vars/virtu.yml create mode 100755 plays/proxmox.yml create mode 100644 roles/proxmox-debian-images/tasks/main.yml create mode 100644 roles/proxmox-debian-images/templates/cron.d/debian-images.j2 diff --git a/group_vars/virtu.yml b/group_vars/virtu.yml new file mode 100644 index 00000000..b999a504 --- /dev/null +++ b/group_vars/virtu.yml @@ -0,0 +1,4 @@ +--- +glob_debian_images: + cron_timer: '39 06 * * *' + rsync_host: "eclat.adm.crans.org" diff --git a/host_vars/gulp.cachan-adm.crans.org.yml b/host_vars/gulp.cachan-adm.crans.org.yml index a8c822db..b44167ae 100644 --- a/host_vars/gulp.cachan-adm.crans.org.yml +++ b/host_vars/gulp.cachan-adm.crans.org.yml @@ -11,6 +11,9 @@ glob_ntp_client: debian_mirror: http://mirror.cachan-adm.crans.org/debian proxmox_mirror: http://mirror.cachan-adm.crans.org/proxmox/debian/pve +loc_debian_images: + rsync_host: 'mirror.cachan-adm.crans.org' + loc_postgres: subnets: - 172.17.10.0/24 diff --git a/plays/proxmox.yml b/plays/proxmox.yml new file mode 100755 index 00000000..cc44d139 --- /dev/null +++ b/plays/proxmox.yml @@ -0,0 +1,8 @@ +#!/usr/bin/env ansible-playbook +--- +- hosts: virtu + vars: + debian_images: '{{ glob_debian_images | default({}) | combine(loc_debian_images | default({})) }}' + roles: + - proxmox-apt-sources + - proxmox-debian-images diff --git a/plays/root.yml b/plays/root.yml index 76ba3d1f..fed28c12 100755 --- a/plays/root.yml +++ b/plays/root.yml @@ -13,6 +13,7 @@ - import_playbook: baie.yml - import_playbook: utilities.yml - import_playbook: slapd.yml +- import_playbook: proxmox.yml - hosts: server,!sssd vars: diff --git a/roles/proxmox-debian-images/tasks/main.yml b/roles/proxmox-debian-images/tasks/main.yml new file mode 100644 index 00000000..a21c22ff --- /dev/null +++ b/roles/proxmox-debian-images/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- name: Auto-sync debian CD images to always have up-to-date Debian images + template: + src: cron.d/debian-images.j2 + dest: /etc/cron.d/debian-images + +- name: Install rsync + apt: + update_cache: true + name: rsync + register: apt_result + retries: 3 + until: apt_result is succeeded + +- name: Initial synchronization to download Debian images + shell: "rsync --verbose --dirs --compress --times --update --delete-after --delete-excluded --include 'debian-[0-9]*-amd64-netinst.iso' --exclude '*' rsync://eclat.adm.crans.org/mirror/cdimage-debian/release/current/amd64/iso-cd/ /var/lib/vz/template/iso/" + register: rsync_output + changed_when: '"debian" in rsync_output.stdout' diff --git a/roles/proxmox-debian-images/templates/cron.d/debian-images.j2 b/roles/proxmox-debian-images/templates/cron.d/debian-images.j2 new file mode 100644 index 00000000..bec7e9f6 --- /dev/null +++ b/roles/proxmox-debian-images/templates/cron.d/debian-images.j2 @@ -0,0 +1,3 @@ +{{ ansible_header | comment }} + +{{ debian_images.cron_timer }} root rsync --info=name1 --dirs --compress --times --update --delete-after --delete-excluded --include 'debian-[0-9]*-amd64-netinst.iso' --exclude '*' rsync://{{ debian_images.rsync_host }}/mirror/cdimage-debian/release/current/amd64/iso-cd/ /var/lib/vz/template/iso/