Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/roles/foreman/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,28 @@
username: "{{ foreman_initial_admin_username }}"
password: "{{ foreman_initial_admin_password }}"
validate_certs: false

- name: Deploy Quadlet container and timer for Foreman reports:daily
# when: foreman_recurring_tasks_enabled | default(true)
block:
- name: Create Quadlet container definitions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have expected to define this quadlet the same way we do for regular services with containers.podman.podman_container. Is that not possible for timers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so I did this way to start it with templated .container and .timer units to get a working prototype quickly and to control the timer behavior directly. Since I found that containers.podman.podman_container doesn’t create .timer units, I had to template that part anyway.

And plan is to refactor it to define the .container using containers.podman.podman_container, which aligns with how other services are handled in foremanctl. But the .timer will remain a small template for now, since neither podman_container nor podman_generate_systemd currently support generating .timer units and they only handle .container (or .service) definitions.

So question would you prefer that all recurring-task containers follow the same podman_container (state: quadlet) pattern, even if each has its own .timer defined separately? @ehelms @evgeni

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think I prefer containers.podman.podman_container to define quadlets, just to make it consistent.

But would also like to open up the following discussion: This PR adds a timer for foreman-rake reports:daily and we expect more to come. A quick glance gives me:

foreman:

15 23 * * *     foreman    /usr/sbin/foreman-rake db:sessions:clear 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log
0 7 * * *       foreman    /usr/sbin/foreman-rake reports:daily 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log
0 5 * * 0       foreman    /usr/sbin/foreman-rake reports:weekly 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log
0 3 1 * *       foreman    /usr/sbin/foreman-rake reports:monthly 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log
30 7 * * *      foreman    /usr/sbin/foreman-rake reports:expire 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log
0 1 * * *      foreman    /usr/sbin/foreman-rake audits:expire 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log
*/30 * * * *    foreman    /usr/sbin/foreman-rake ldap:refresh_usergroups 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log
0 6 * * 0       foreman    /usr/sbin/foreman-rake notifications:clean 2>&1 | gawk '{ print strftime("[\%Y-\%m-\%d \%H:\%M:\%S]"), $0 }' >>/var/log/foreman/cron.log

katello:

00 22 * * 0	root	foreman-rake katello:delete_orphaned_content RAILS_ENV=production >/dev/null 2>&1
00 18 * * 0     root    foreman-rake katello:refresh_alternate_content_sources >/dev/null 2>&1

foreman-tasks:

45 19 * * *    foreman    /usr/sbin/foreman-rake foreman_tasks:cleanup >>/var/log/foreman/cron.log 2>&1

Now, given they all use foreman-rake <something>, I wonder if we can create a template (container) service, and then use timer units to start different instances of this service, running different subcommands?

Sort of like we do for the different dynflow workers today.

ansible.builtin.template:
src: foreman-recurring-daily.container.j2
dest: "/etc/containers/systemd/foreman-reports-daily.container"
mode: "0644"

- name: Create Quadlet timer definitions
ansible.builtin.template:
src: foreman-recurring-daily.timer.j2
dest: "/etc/containers/systemd/foreman-reports-daily.timer"
mode: "0644"

- name: Reload systemd to register new Quadlet units
ansible.builtin.systemd:
daemon_reload: true

- name: Enable and start Foreman reports:daily timer
ansible.builtin.systemd:
name: "foreman-reports-daily.timer"
enabled: true
state: started
14 changes: 14 additions & 0 deletions src/roles/foreman/templates/foreman-reports-daily.container.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Foreman recurring task: reports:daily

[Container]
Image={{ foreman_container_image }}:{{ foreman_container_tag }}
Exec=foreman-rake reports:daily
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will require all the secrets and configs mounted like the normal container does, otherwise it can't access the DB and stuff

User=foreman
WorkingDir=/usr/share/foreman
Volume=/etc/foreman:/etc/foreman:ro
Volume=/var/lib/foreman:/var/lib/foreman
Comment on lines +9 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do these volumes come from?

Network=host

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions src/roles/foreman/templates/foreman-reports-daily.timer.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Timer for Foreman reports:daily task

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
Loading