From 6f5455f6c525d5e5acedc8f5fcace1c2a9279423 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 28 Apr 2021 16:28:39 +0200 Subject: Adds unattended upgrades as role --- src/BaseServerSetup.php | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'src/BaseServerSetup.php') diff --git a/src/BaseServerSetup.php b/src/BaseServerSetup.php index 7ff1efb..206d773 100644 --- a/src/BaseServerSetup.php +++ b/src/BaseServerSetup.php @@ -2,11 +2,11 @@ namespace Dweipert\DevOps\BaseServerSetup; +use Dweipert\DevOps\UnattendedUpgrades\UnattendedUpgrades; use PHPIAC\Module\State; use PHPIAC\Modules\AptModule; use PHPIAC\Modules\CopyModule; use PHPIAC\Modules\GitModule; -use PHPIAC\Modules\TemplateModule; use PHPIAC\Modules\UfwModule; use PHPIAC\Modules\UserModule; use PHPIAC\Role\RoleInterface; @@ -17,8 +17,7 @@ class BaseServerSetup implements RoleInterface public function __invoke(array $config = []): array { $config = array_replace_recursive( - include __DIR__ . '/unattended-upgrades/unattended-upgrades.php', - [ + ['unattended_upgrades' => [ 'unattended_origins_patterns' => [ 'o=${distro_id},a=${distro_codename}', 'o=${distro_id},a=${distro_codename}-security', @@ -26,32 +25,13 @@ class BaseServerSetup implements RoleInterface 'unattended_mail' => $config['mail'], 'unattended_automatic_reboot' => true, 'unattended_syslog_enable' => true, - ], + ]], $config ); return [ # setup unattended upgrades - (new Task())->setModule(new AptModule([ - 'package' => 'unattended-upgrades', - 'updateCache' => true, - ])), - (new Task())->setModule(new TemplateModule([ - 'src' => __DIR__ . '/unattended-upgrades/auto-upgrades.twig', - 'dest' => '/etc/apt/apt.conf.d/20auto-upgrades', - 'vars' => $config, - 'owner' => 'root', - 'group' => 'root', - 'mode' => 0644, - ])), - (new Task())->setModule(new TemplateModule([ - 'src' => __DIR__ . '/unattended-upgrades/unattended-upgrades.twig', - 'dest' => '/etc/apt/apt.conf.d/50unattended-upgrades', - 'vars' => $config, - 'owner' => 'root', - 'group' => 'root', - 'mode' => 0644, - ])), + ...(new UnattendedUpgrades())($config['unattended_upgrades']), # setup user (new Task())->setModule(new AptModule([ @@ -66,7 +46,7 @@ class BaseServerSetup implements RoleInterface ])), (new Task())->setModule(new CopyModule([ 'src' => '~/.ssh', - 'dest' => '/home/' . $config['username'], + 'dest' => '/home/' . $config['username'] . '/.ssh', 'owner' => $config['username'], 'group' => $config['username'], 'remoteSrc' => true, -- cgit v1.2.3