From d8ff9ddb11d1900c3e8b979d13a0bd508b8809d3 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 3 Dec 2023 17:43:49 +1100 Subject: [PATCH] feat: setup/manage dnf-autoupdate - create service to run dnf update - create timer to call the service - manage settings via params --- site/profiles/manifests/yum/autoupdater.pp | 18 ++++++++++++++++++ site/profiles/manifests/yum/global.pp | 4 ++++ .../templates/yum/autoupdate_service.erb | 6 ++++++ .../templates/yum/autoupdate_timer.erb | 10 ++++++++++ 4 files changed, 38 insertions(+) create mode 100644 site/profiles/manifests/yum/autoupdater.pp create mode 100644 site/profiles/templates/yum/autoupdate_service.erb create mode 100644 site/profiles/templates/yum/autoupdate_timer.erb diff --git a/site/profiles/manifests/yum/autoupdater.pp b/site/profiles/manifests/yum/autoupdater.pp new file mode 100644 index 0000000..17b2935 --- /dev/null +++ b/site/profiles/manifests/yum/autoupdater.pp @@ -0,0 +1,18 @@ +# profiles::yum::autoupdater +# +# manage automatic updates for dnf +# +class profiles::yum::autoupdater ( + String $on_calendar = '*-*-* 05:00:00', + Integer $randomized_delay_sec = 1800, + Boolean $enabled = true, +) { + + # Ensure the timer is enabled and running + systemd::timer { 'dnf-autoupdate.timer': + timer_content => template('profiles/yum/autoupdate_timer.erb'), + service_content => template('profiles/yum/autoupdate_service.erb'), + active => true, + enable => true, + } +} diff --git a/site/profiles/manifests/yum/global.pp b/site/profiles/manifests/yum/global.pp index eca5715..119230e 100644 --- a/site/profiles/manifests/yum/global.pp +++ b/site/profiles/manifests/yum/global.pp @@ -86,4 +86,8 @@ class profiles::yum::global ( class { 'profiles::yum::puppet7': managed_repos => $managed_repos, } + + # setup dnf-autoupdate + include profiles::yum::autoupdater + } diff --git a/site/profiles/templates/yum/autoupdate_service.erb b/site/profiles/templates/yum/autoupdate_service.erb new file mode 100644 index 0000000..988b272 --- /dev/null +++ b/site/profiles/templates/yum/autoupdate_service.erb @@ -0,0 +1,6 @@ +[Unit] +Description=dnf-autoupdater-service + +[Service] +Type=oneshot +ExecStart=/usr/bin/dnf update -y diff --git a/site/profiles/templates/yum/autoupdate_timer.erb b/site/profiles/templates/yum/autoupdate_timer.erb new file mode 100644 index 0000000..6dcc3cb --- /dev/null +++ b/site/profiles/templates/yum/autoupdate_timer.erb @@ -0,0 +1,10 @@ +[Unit] +Description=dnf-autoupdater-timer + +[Timer] +OnCalendar=<%= @on_calendar %> +RandomizedDelaySec=<%= @randomized_delay_sec %> +Persistent=true + +[Install] +WantedBy=timers.target