mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-28 21:32:20 +00:00
feat(Template): render the osimage pkglist into the autoinstall package list
A Subiquity autoinstall installs what its user-data packages list names, and the templates could only name a fixed set, so the osimage pkglist reached an Ubuntu node through ospkgs after the first boot. The preseed token has no autoinstall form: the package list is YAML, one item per line. A list line that carries #INCLUDE_DEFAULT_PKGLIST_AUTOINSTALL# is now replaced by one item per pkglist package at the same indentation, with includes followed and without repeating the items the template lists above it. The line is replaced in the include pass of subvars, so a site template that includes the stock one is served too. A plain name and a task are installed this way, and a comment after them ends the record. A version pin or a target release stays with ospkgs, because the installer runs apt-get without --allow-downgrades and a pin can require one, and so does a name with an architecture qualifier, because a foreign architecture is enabled by a postscript that runs later. A record that begins with a removal or a group is left out whole, as ospkgs removes or installs it whole, and so are a removal written with a trailing hyphen, markers and preseed directives. A list that carries a #ENV: setting or an unreadable include is left to ospkgs whole. So is the list of an osimage with environvar, which mkinstall now hands over, and such an image's pkgdir mirrors stay out of the installer's sources as well: those variables reach apt-get only through ospkgs, and a mirror may need them. An osimage without a pkglist loses only the token line. The installer's apt configuration turns recommended packages off, as ospkgs installs the list without them; curtin writes that setting into the target, where the template removes it with the installer's sources. Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com>
This commit is contained in:
@@ -173,6 +173,11 @@ sub subvars {
|
||||
$inc =~ s/#INCLUDE_DEFAULT_RMPKGLIST_S#/#INCLUDE_RMPKGLIST:$pkglistfile#/g;
|
||||
}
|
||||
|
||||
# osimage environvar reaches apt-get through ospkgs alone, so such an image installs its list there,
|
||||
# and its pkgdir mirrors, which may need those variables too, stay out of the installer's sources
|
||||
my $environvar_set = ( $namedargs{environvar} // '' ) =~ /\S/;
|
||||
my $installer_pkgdirs = $environvar_set ? undef : $namedargs{pkgdirs};
|
||||
my @autoinstall;
|
||||
if (("ubuntu" eq $platform) || ("debian" eq $platform)) {
|
||||
|
||||
# since debian/ubuntu uses a preseed file instead of a kickstart file, pkglist
|
||||
@@ -186,6 +191,7 @@ sub subvars {
|
||||
if ($allpkglist =~ /#INCLUDEBAD:(.*)#/) {
|
||||
return "$1";
|
||||
}
|
||||
@autoinstall = ubuntu_autoinstall_packages( xCAT::Postage->get_pkglist_records($pkglistfile) ) unless $environvar_set;
|
||||
$allpkglist =~ s/,/ /g;
|
||||
$inc =~ s/#INCLUDE_DEFAULT_PKGLIST_PRESEED#/$allpkglist/g;
|
||||
|
||||
@@ -364,7 +370,7 @@ sub subvars {
|
||||
$inc =~ s/#INSTALL_SOURCES_IN_PRE#/$source_in_pre/g;
|
||||
if (("ubuntu" eq $platform) || ("debian" eq $platform)) {
|
||||
$inc =~ s/#INCLUDE_OSIMAGE_PKGDIR#/$pkgdirs[-1]/;
|
||||
$inc =~ s/#UBUNTU_SUBIQUITY_APT_CONFIG#/ubuntu_subiquity_apt_config($media_dir, $namedargs{osarch}, $namedargs{pkgdirs})/eg;
|
||||
$inc =~ s/#UBUNTU_SUBIQUITY_APT_CONFIG#/ubuntu_subiquity_apt_config($media_dir, $namedargs{osarch}, $installer_pkgdirs)/eg;
|
||||
}
|
||||
$inc =~ s/#WRITEREPO#/$writerepo/g;
|
||||
}
|
||||
@@ -377,7 +383,9 @@ sub subvars {
|
||||
$inc =~ s/#INCLUDE_NOP:([^#^\n]+)#/includefile($1,1,0)/eg;
|
||||
$inc =~ s/#XCATVAR:([^#]+)#/envvar($1)/eg;
|
||||
$inc =~ s/#ENV:([^#]+)#/envvar($1)/eg;
|
||||
$inc =~ s/#UBUNTU_SUBIQUITY_APT_CONFIG#/ubuntu_subiquity_apt_config($media_dir, $namedargs{osarch}, $namedargs{pkgdirs})/eg;
|
||||
$inc =~ s/#UBUNTU_SUBIQUITY_APT_CONFIG#/ubuntu_subiquity_apt_config($media_dir, $namedargs{osarch}, $installer_pkgdirs)/eg;
|
||||
# in the include pass, so a template that includes the stock Subiquity one gets its list as well
|
||||
$inc =~ s/^((?:[ \t]*- [^\n]*\n)*)([ \t]*)- #INCLUDE_DEFAULT_PKGLIST_AUTOINSTALL#[ \t]*\n/$1 . ubuntu_autoinstall_items($2, $1, \@autoinstall)/meg;
|
||||
$inc =~ s/#SUBIQUITYINSTALLNIC#/subiquity_install_nic()/eg;
|
||||
$inc =~ s/#SUBIQUITYINSTALLMAC#/subiquity_install_mac()/eg;
|
||||
$inc =~ s/#MACHINEPASSWORD#/machinepassword()/eg;
|
||||
@@ -1764,6 +1772,59 @@ sub subiquity_install_mac {
|
||||
return $macaddress;
|
||||
}
|
||||
|
||||
# ubuntu_autoinstall_packages: the packages of the pkglist records (whole lines, as
|
||||
# get_pkglist_records returns them) that a Subiquity autoinstall can install through its packages
|
||||
# list. A record holds one or more space-separated packages, as the preseed path reads it, each a
|
||||
# plain name or a task. A version pin or a target release stays with ospkgs, because the installer
|
||||
# runs apt-get without --allow-downgrades and a pin can require one, and so does a name with an
|
||||
# architecture qualifier, because a foreign architecture is enabled by a postscript that runs later. A preseed directive, told by its question type, a record that begins with a removal
|
||||
# or a group, which ospkgs removes or installs whole, a removal written with a trailing hyphen as
|
||||
# apt-get reads it, or a marker has
|
||||
# no autoinstall form, a comment ends the packages of a record, and a record with a token that is
|
||||
# none of these is left out whole. A list
|
||||
# that carries a #ENV: setting, which only ospkgs can pass to apt-get, or an unreadable include is
|
||||
# left to ospkgs whole; ospkgs still applies the whole list after the install.
|
||||
my %PRESEED_TYPE = map { $_ => 1 } qw(string boolean select multiselect note password text seen title error);
|
||||
|
||||
sub ubuntu_autoinstall_packages
|
||||
{
|
||||
my @records = grep { defined } @_;
|
||||
return () if grep { /#(?:ENV:|INCLUDEBAD:)/ } @records;
|
||||
my (@packages, %seen);
|
||||
RECORD: foreach my $record (@records) {
|
||||
my @tokens = grep { length } split( /\s+/, $record );
|
||||
next unless @tokens;
|
||||
next if @tokens >= 3 && $PRESEED_TYPE{ $tokens[2] };
|
||||
next if $tokens[0] =~ /^[-@]/; # ospkgs removes or installs the whole record
|
||||
my @found;
|
||||
foreach my $token (@tokens) {
|
||||
last if $token =~ /^#/;
|
||||
next if $token =~ /^[-@]/ || $token =~ /-$/;
|
||||
next RECORD unless $token =~ m{^[a-z0-9][a-z0-9+.-]*(?::[a-z0-9-]+)?(?:[=/][^\s/=]+|\^)?$};
|
||||
next if $token =~ m{[:=/]};
|
||||
push @found, $token;
|
||||
}
|
||||
push @packages, grep { !$seen{$_}++ } @found;
|
||||
}
|
||||
return @packages;
|
||||
}
|
||||
|
||||
# ubuntu_autoinstall_items: the list items for the pkglist packages at the token's indentation,
|
||||
# leaving out packages the items above the token already name, each quoted so a name such as null
|
||||
# or true stays a string. The time daemons exclude each
|
||||
# other, so when the template names one, the pkglist's stay with ospkgs, as they did before.
|
||||
my %UBUNTU_TIME_DAEMON = map { $_ => 1 } qw(chrony ntp ntpsec ntpdate ntpsec-ntpdate openntpd systemd-timesyncd);
|
||||
|
||||
sub ubuntu_autoinstall_items
|
||||
{
|
||||
my ($indent, $listed, $packages) = @_;
|
||||
my %named = map { $_ => 1 } ( $listed =~ /^[ \t]*- (\S+)[ \t]*$/mg );
|
||||
my $fixed_time_daemon = grep { $UBUNTU_TIME_DAEMON{$_} } keys %named;
|
||||
my @items = grep { !$named{$_} } @$packages;
|
||||
@items = grep { !$UBUNTU_TIME_DAEMON{ (split /[:=\/^]/, $_)[0] } } @items if $fixed_time_daemon;
|
||||
return join( '', map { "$indent- \"$_\"\n" } @items );
|
||||
}
|
||||
|
||||
sub ubuntu_subiquity_apt_mirror
|
||||
{
|
||||
my ($osarch) = @_;
|
||||
@@ -1816,6 +1877,7 @@ sub ubuntu_subiquity_apt_config
|
||||
' apt:',
|
||||
' preserve_sources_list: false',
|
||||
' geoip: false',
|
||||
q( conf: 'APT::Install-Recommends "false";'),
|
||||
' mirror-selection:',
|
||||
' primary:',
|
||||
" - uri: $online_mirror",
|
||||
@@ -1854,6 +1916,7 @@ sub ubuntu_subiquity_apt_config
|
||||
' preserve_sources_list: false',
|
||||
' fallback: offline-install',
|
||||
' geoip: false',
|
||||
q( conf: 'APT::Install-Recommends "false";'),
|
||||
' disable_suites:',
|
||||
' - updates',
|
||||
' - backports',
|
||||
|
||||
@@ -895,6 +895,7 @@ sub mkinstall {
|
||||
my $partitionfile;
|
||||
my $pkgdir;
|
||||
my $pkgdirval;
|
||||
my $environvar;
|
||||
my @mirrors;
|
||||
my $pkglistfile;
|
||||
my $imagename; # set it if running of 'nodeset osimage=xxx'
|
||||
@@ -917,12 +918,13 @@ sub mkinstall {
|
||||
if (!$osimagetab) {
|
||||
$osimagetab = xCAT::Table->new('osimage', -create => 1);
|
||||
}
|
||||
(my $ref) = $osimagetab->getAttribs({ imagename => $imagename }, 'osvers', 'osarch', 'profile', 'provmethod');
|
||||
(my $ref) = $osimagetab->getAttribs({ imagename => $imagename }, 'osvers', 'osarch', 'profile', 'provmethod', 'environvar');
|
||||
if ($ref) {
|
||||
$img_hash{$imagename}->{osver} = $ref->{'osvers'};
|
||||
$img_hash{$imagename}->{osarch} = $ref->{'osarch'};
|
||||
$img_hash{$imagename}->{profile} = $ref->{'profile'};
|
||||
$img_hash{$imagename}->{provmethod} = $ref->{'provmethod'};
|
||||
$img_hash{$imagename}->{environvar} = $ref->{'environvar'};
|
||||
if (!$linuximagetab) {
|
||||
$linuximagetab = xCAT::Table->new('linuximage', -create => 1);
|
||||
}
|
||||
@@ -995,6 +997,7 @@ sub mkinstall {
|
||||
|
||||
$tmplfile = $ph->{template};
|
||||
$pkgdirval = $ph->{pkgdir};
|
||||
$environvar = $ph->{environvar};
|
||||
my @pkgdirlist = split(/,/, $pkgdirval);
|
||||
foreach (@pkgdirlist) {
|
||||
if ($_ =~ /^http|ssh/) {
|
||||
@@ -1123,8 +1126,9 @@ sub mkinstall {
|
||||
$platform,
|
||||
$partitionfile,
|
||||
\%tmpl_hash,
|
||||
osarch => $arch,
|
||||
pkgdirs => $pkgdirval
|
||||
osarch => $arch,
|
||||
pkgdirs => $pkgdirval,
|
||||
environvar => $environvar
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user