From dfa81fe29a6be169d6ed2803c4bedcd211b16d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 13 Jan 2022 23:15:11 +0100 Subject: Nspawn cleanup. --- manifests/os/arch.pp | 15 +++++++++------ manifests/os/debian.pp | 47 ++++++++++++++++++----------------------------- 2 files changed, 27 insertions(+), 35 deletions(-) (limited to 'manifests/os') diff --git a/manifests/os/arch.pp b/manifests/os/arch.pp index e5fc210..d9bd258 100644 --- a/manifests/os/arch.pp +++ b/manifests/os/arch.pp @@ -1,14 +1,17 @@ define nspawn::os::arch ( - String $machine = $name, + String $template_name = $name, + String $template_dir = $nspawn::template_dir, ) { ensure_packages(['arch-install-scripts']) - $machine_path = "/var/lib/machines/${machine}" + $root = "${template_dir}/${template_name}" - exec { "/usr/bin/pacstrap '${machine_path}' base puppet": - creates => "${machine_path}/etc/os-release", + file { $root: + ensure => directory, + } -> exec { "/usr/bin/pacstrap '${root}' base puppet": + creates => "${root}/etc/os-release", + } -> nspawn::util::enable_networkd { $template_name: + template_dir => $template_dir, } - - nspawn::util::enable_networkd { $machine: } } diff --git a/manifests/os/debian.pp b/manifests/os/debian.pp index ff687dd..e7e7a21 100644 --- a/manifests/os/debian.pp +++ b/manifests/os/debian.pp @@ -1,10 +1,12 @@ # TODO rename this to image-setup define nspawn::os::debian ( String $os_version, - String $machine = $name, + String $template_name = $name, + String $template_dir = $nspawn::template_dir, ) { - $root = "/var/lib/machines/debian-${os_version}.base" + $root = "${template_dir}/${template_name}" + $pkg_pos = 'var/tmp' ensure_packages(['debootstrap']) @@ -13,34 +15,35 @@ define nspawn::os::debian ( } $puppet_deb = "puppet7-release-${os_version}.deb" - $puppet_deb_path = "${root}/opt/${puppet_deb}" + $puppet_deb_path = "${root}/${pkg_pos}/${puppet_deb}" file { $puppet_deb_path: ensure => file, source => "https://apt.puppet.com/${puppet_deb}" } - $running = $facts['machined-info'][$machine] != undef and $facts['machined-info'][$machine]['State'] == 'running' + $running = $facts['machined-info'][$template_name] != undef + and $facts['machined-info'][$template_name]['State'] == 'running' if $running { # TODO - notify { "Notify skipping ${machine} setup": - message => "Skipping setup for ${machine}, already running", + notify { "Notify skipping ${template_name} setup": + message => "Skipping setup for ${template_name}, already running", } } else { - exec { "Set up puppet repo for ${machine}": + exec { "Set up puppet repo for ${template_name}": subscribe => File[$puppet_deb_path], command => [ '/usr/bin/systemd-nspawn', - '-M', $machine, + '-M', $template_name, '--quiet', '/bin/sh', '-c', - "dpkg -i '/opt/puppet7-release-${os_version}.deb' && apt update" + "dpkg -i '/${pkg_pos}/puppet7-release-${os_version}.deb' && apt update" ], } - exec { "install puppet-agent on ${machine}": + exec { "install puppet-agent on ${template_name}": command => [ '/usr/bin/systemd-nspawn', - '-M', $machine, + '-M', $template_name, '--quiet', 'apt', 'install', 'puppet-agent', ], @@ -48,24 +51,10 @@ define nspawn::os::debian ( } } - - exec { "Enable puppet on ${machine}": - command => [ '/usr/bin/systemd-nspawn', - '-M', $machine, - '--quiet', - 'systemctl', 'enable', 'puppet', - ], - creates => "${root}/etc/systemd/system/multi-user.target.wants/puppet.service", + nspawn::util::disable_networking { $template_name: + template_dir => $template_dir, } - - file { "${root}/etc/puppetlabs/puppet/puppet.conf": - ensure => file, - content => @(EOF) - [main] - server = busting.adrift.space - | EOF + nspawn::util::enable_networkd { $template_name: + template_dir => $template_dir, } - - nspawn::util::disable_networking { $machine: } - nspawn::util::enable_networkd { $machine: } } -- cgit v1.2.3