Hello, As sys admin I use puppet to push config to servers.
It is very simple, puppet detect a file is not the same than the reference, copy the file, restart the daemon or trigger a command if need. Here come urpmi, can you push by force the urpmi.cfg and make it work using some --force and --do-it-even-it-is-really-not-clean but each time an urpmi command is called the config file written again. Then the file is changed, making puppet updating the urpmi.cfg again and again. To avoid this problem I wrote the attached script: it take as argument the path to an urpmi.cfg and synchronize the config found with the real urpmi.cfg. - removed media are removed properly - the media.cfg used as template is unchanged - urpmi.update is called to update the index - urpmi base is locked to avoid race condition In cases this can be usefull. Ideas and patches welcome. -- Olivier Thauvin CNRS - LATMOS ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖
#!/usr/bin/perl
use strict;
use warnings;
use urpm;
use urpm::cfg;
use urpm::media;
use urpm::args;
use urpm::download;
use Getopt::Long;
use Pod::Usage;
GetOptions(
help => sub { pod2usage() },
);# or pod2sage(1);
my ($config) = @ARGV;
my $template = urpm::cfg::load_config($config);
{
my $urpm = urpm->new_parse_cmdline or exit(1);
my $_urpmi_lock = urpm::lock::urpmi_db(
$urpm,
'exclusive',
wait => 1,
);
urpm::media::read_config($urpm);
my %media_to_update = ();
foreach my $medium (@{ $urpm->{media} || [] }) {
my ($tlpmedia) = (grep { $_->{name} eq $medium->{name} }
@{ $template->{media} || [] });
if (! $tlpmedia) {
my @selected = urpm::media::select_media_by_name($urpm, [
$medium->{name} ],
!$urpm->{options}{fuzzy});
urpm::media::remove_media($urpm, \@selected);
} else {
%{ $medium } = ();
%{ $medium } = %{ $tlpmedia };
}
}
foreach my $medium (@{ $template->{media} || [] }) {
if (!grep { $_->{name} eq $medium->{name} }
(@{ $urpm->{media} || [] })) {
push(@{ $urpm->{media} }, $medium);
}
}
$urpm->{modified} = 1;
urpm::media::write_config($urpm);
}
system('/usr/sbin/urpmi.update', '-a', '-q');
pgps8PBU2zqdF.pgp
Description: PGP signature
