1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mageia-dev] puppet and the urpmi config
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:mageia-dev%40mageia.org?Subject=Re%3A%20%5BMageia-dev%5D%20puppet%20and%20the%20urpmi%20config&In-Reply-To=%3C20120718122906.GW3708%40virgo.home.nanardon.zarb.org%3E">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="017466.html">
<LINK REL="Next" HREF="017457.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mageia-dev] puppet and the urpmi config</H1>
<B>Olivier Thauvin</B>
<A HREF="mailto:mageia-dev%40mageia.org?Subject=Re%3A%20%5BMageia-dev%5D%20puppet%20and%20the%20urpmi%20config&In-Reply-To=%3C20120718122906.GW3708%40virgo.home.nanardon.zarb.org%3E"
TITLE="[Mageia-dev] puppet and the urpmi config">nanardon at nanardon.zarb.org
</A><BR>
<I>Wed Jul 18 14:29:06 CEST 2012</I>
<P><UL>
<LI>Previous message: <A HREF="017466.html">[Mageia-dev] LSI Logic Megaraid SAS not supported with install dvd
</A></li>
<LI>Next message: <A HREF="017457.html">[Mageia-dev] puppet and the urpmi config
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#17450">[ date ]</a>
<a href="thread.html#17450">[ thread ]</a>
<a href="subject.html#17450">[ subject ]</a>
<a href="author.html#17450">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>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
♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖
-------------- next part --------------
#!/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');
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: </pipermail/mageia-dev/attachments/20120718/16773ec7/attachment.asc>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="017466.html">[Mageia-dev] LSI Logic Megaraid SAS not supported with install dvd
</A></li>
<LI>Next message: <A HREF="017457.html">[Mageia-dev] puppet and the urpmi config
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#17450">[ date ]</a>
<a href="thread.html#17450">[ thread ]</a>
<a href="subject.html#17450">[ subject ]</a>
<a href="author.html#17450">[ author ]</a>
</LI>
</UL>
<hr>
<a href="https://www.mageia.org/mailman/listinfo/mageia-dev">More information about the Mageia-dev
mailing list</a><br>
</body></html>
|