Move tarball compression to background service;Housekeeping
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Danny Bessems 2022-11-23 10:25:35 +01:00
parent 0d7b1ab269
commit c9a8598a35
5 changed files with 49 additions and 12 deletions

View File

@ -0,0 +1,4 @@
- name: Disable crontab job
ansible.builtin.cron:
name: firstboot
state: absent

View File

@ -1,10 +1,5 @@
- name: Compress tarballs
community.general.archive:
dest: /opt/metacluster/container-images/image-tarballs.tgz
path: /opt/metacluster/container-images/*.tar
format: gz
remove: yes
ignore_errors: yes
- import_tasks: service.yml
- import_tasks: cron.yml
- name: Cleanup tempfile
ansible.builtin.file:
@ -12,11 +7,6 @@
state: absent
when: kubeconfig.path is defined
- name: Disable crontab job
ansible.builtin.cron:
name: firstboot
state: absent
- name: Reboot host
ansible.builtin.shell:
cmd: /usr/sbin/reboot now

View File

@ -0,0 +1,24 @@
- name: Create tarball compression service
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: "{{ item.mode | default(omit) }}"
vars:
_template:
service:
name: compressTarballs
executable: /opt/firstboot/compresstarballs.sh
workingdir: /opt/metacluster/container-images/
loop:
- src: compresstarballs.j2
dest: "{{ _template.service.executable }}"
mode: o+x
- src: systemdunit.j2
dest: /etc/systemd/system/{{ _template.service.name }}.service
- name: Enable tarball compression service
ansible.builtin.systemd:
name: compressTarballs
enabled: yes

View File

@ -0,0 +1,10 @@
#!/bin/bash
# Change working directory
popd {{ _template.service.workingdir }}
# Compress *.tar files
if tar -czf image-tarballs.tgz *.tar; then
# Disable systemd unit
systemctl disable {{ _template.service.name }}
fi

View File

@ -0,0 +1,9 @@
[Unit]
Description={{ _template.service.name }}
[Service]
ExecStart={{ _template.service.executable }}
Nice=10
[Install]
WantedBy=multi-user.target