From 854912f814140e38f871eceb58cd7a52f51f46fb Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Mon, 30 Nov 2020 11:55:16 -0500 Subject: [PATCH] Add zuul-registry crontab entry This is so we can prune images regularly. Change-Id: If1d34ac0a6c2eece92b854e6fe0bdf3602fbb02b Signed-off-by: Paul Belanger --- defaults/main.yaml | 6 ++++++ tasks/config.yaml | 9 +++++++++ templates/etc/cron.d/zuul-registry.j2 | 4 ++++ tests/playbooks/run.yaml | 13 +++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 templates/etc/cron.d/zuul-registry.j2 diff --git a/defaults/main.yaml b/defaults/main.yaml index 65baa9a..e8e3ea6 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -46,6 +46,12 @@ zuul_registry_file_ssl_key_mode: 0600 zuul_registry_file_ssl_key_owner: "{{ zuul_registry_user_name }}" zuul_registry_file_ssl_key_src: etc/zuul-registry/ssl/cert.key +zuul_registry_file_crontab_dest: /etc/cron.d/zuul-registry +zuul_registry_file_crontab_group: root +zuul_registry_file_crontab_mode: 0644 +zuul_registry_file_crontab_owner: root +zuul_registry_file_crontab_src: etc/cron.d/zuul-registry.j2 + # tasks/install.yaml zuul_registry_git_dest: "{{ ansible_user_dir }}/src/opendev.org/zuul/zuul-registry" zuul_registry_git_uri: https://opendev.org/zuul/zuul-registry diff --git a/tasks/config.yaml b/tasks/config.yaml index f6f2545..4591a0a 100644 --- a/tasks/config.yaml +++ b/tasks/config.yaml @@ -53,3 +53,12 @@ owner: "{{ zuul_registry_file_ssl_key_owner }}" src: "{{ zuul_registry_file_ssl_key_src }}" register: zuul_registry_file_ssl_key + +- name: Install zuul-registry crontab + become: true + template: + dest: "{{ zuul_registry_file_crontab_dest }}" + group: "{{ zuul_registry_file_crontab_group }}" + mode: "{{ zuul_registry_file_crontab_mode }}" + owner: "{{ zuul_registry_file_crontab_owner }}" + src: "{{ zuul_registry_file_crontab_src }}" diff --git a/templates/etc/cron.d/zuul-registry.j2 b/templates/etc/cron.d/zuul-registry.j2 new file mode 100644 index 0000000..bba3df8 --- /dev/null +++ b/templates/etc/cron.d/zuul-registry.j2 @@ -0,0 +1,4 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +0 3 * * * {{ zuul_registry_user_name }} {{ zuul_registry_pip_virtualenv | default('/usr/local') }}/bin/zuul-regsitry -c {{ zuul_registry_file_registry_yaml_dest }} prune diff --git a/tests/playbooks/run.yaml b/tests/playbooks/run.yaml index 1f7eb4f..f9fee1d 100644 --- a/tests/playbooks/run.yaml +++ b/tests/playbooks/run.yaml @@ -91,6 +91,19 @@ - zuul_registry_git_dest_stat.stat.isdir when: zuul_registry_install_method == 'git' + - name: Register /etc/cron.d/zuul-registry + stat: + path: /etc/cron.d/zuul-registry + register: zuul_registry_crontab_stat + + - name: Assert zuul_registry_crontab_stat tests + assert: + that: + - zuul_registry_crontab_stat.stat.exists + - zuul_registry_crontab_stat.stat.isreg + - zuul_registry_crontab_stat.stat.pw_name == 'root' + - zuul_registry_crontab_stat.stat.gr_name == 'root' + - name: Register /etc/systemd/system/zuul-registry.service stat: path: /etc/systemd/system/zuul-registry.service