1Rex::Commands::Pkg(3) User Contributed Perl DocumentationRex::Commands::Pkg(3)
2
3
4

NAME

6       Rex::Commands::Pkg - Install/Remove Software packages
7

DESCRIPTION

9       With this module you can install packages and files.
10

SYNOPSIS

12        pkg "somepkg",
13          ensure => "present";
14        pkg "somepkg",
15          ensure => "latest",
16          on_change => sub {
17            say "package was updated.";
18            service someservice => "restart";
19          };
20        pkg "somepkg",
21          ensure => "absent";
22

EXPORTED FUNCTIONS

24   pkg($package, %options)
25       Since: 0.45
26
27       Use this resource to install or update a package. This resource will
28       generate reports.
29
30        pkg "httpd",
31          ensure    => "latest",    # ensure that the newest version is installed (auto-update)
32          on_change => sub { say "package was installed/updated"; };
33
34        pkg "httpd",
35          ensure => "absent";    # remove the package
36
37        pkg "httpd",
38          ensure => "present";   # ensure that some version is installed (no auto-update)
39
40        pkg "httpd",
41          ensure => "2.4.6";    # ensure that version 2.4.6 is installed
42
43        pkg "apache-server",    # with a custom resource name
44          package => "httpd",
45          ensure  => "present";
46
47   install($type, $data, $options)
48       The install function can install packages (for CentOS, OpenSuSE and
49       Debian) and files.
50
51       If you need reports, please use the pkg() resource.
52
53       installing a package (This is only supported on CentOS, OpenSuSE and
54       Debian systems.)
55                task "prepare", "server01", sub {
56                  install package => "perl";
57
58                  # or if you have to install more packages.
59                  install package => [
60                                 "perl",
61                                 "ntp",
62                                 "dbus",
63                                 "hal",
64                                 "sudo",
65                                 "vim",
66                               ];
67                };
68
69       installing a file
70               This is deprecated since 0.9. Please use File file instead.
71
72                task "prepare", "server01", sub {
73                  install file => "/etc/passwd", {
74                               source => "/export/files/etc/passwd",
75                               owner  => "root",
76                               group  => "root",
77                               mode  => 644,
78                             };
79                };
80
81       installing a file and do something if the file was changed.
82                task "prepare", "server01", sub {
83                  install file => "/etc/httpd/apache2.conf", {
84                               source   => "/export/files/etc/httpd/apache2.conf",
85                               owner    => "root",
86                               group    => "root",
87                               mode    => 644,
88                               on_change => sub { say "File was modified!"; }
89                             };
90                };
91
92       installing a file from a template.
93                task "prepare", "server01", sub {
94                  install file => "/etc/httpd/apache2.tpl", {
95                               source   => "/export/files/etc/httpd/apache2.conf",
96                               owner    => "root",
97                               group    => "root",
98                               mode    => 644,
99                               on_change => sub { say "File was modified!"; },
100                               template  => {
101                                          greeting => "hello",
102                                          name    => "Ben",
103                                        },
104                             };
105                };
106
107       This function supports the following hooks:
108
109       before  This gets executed before everything is done. The return value
110               of this hook overwrite the original parameters of the function-
111               call.
112
113       before_change
114               This gets executed right before the new package is installed.
115               This hook is only available for package installations. If you
116               need file hooks, you have to use the file() function.
117
118       after_change
119               This gets executed right after the new package was installed.
120               This hook is only available for package installations. If you
121               need file hooks, you have to use the file() function.
122
123       after   This gets executed right before the install() function returns.
124
125   remove($type, $package, $options)
126       This function will remove the given package from a system.
127
128        task "cleanup", "server01", sub {
129          remove package => "vim";
130        };
131
132   update_system
133       This function does a complete system update.
134
135       For example apt-get upgrade or yum update.
136
137        task "update-system", "server1", sub {
138          update_system;
139        };
140
141       If you want to get the packages that where updated, you can use the
142       on_change hook.
143
144        task "update-system", "server1", sub {
145          update_system
146            on_change => sub {
147              my (@modified_packages) = @_;
148              for my $pkg (@modified_packages) {
149                say "Name: $pkg->{name}";
150                say "Version: $pkg->{version}";
151                say "Action: $pkg->{action}";   # some of updated, installed or removed
152              }
153            };
154        };
155
156       Options for update_system
157
158       update_metadata
159           Set to TRUE if the package metadata should be updated. Since 1.5
160           default to FALSE if possible. Before 1.5 it depends on the package
161           manager.
162
163       update_package
164           Set to TRUE if you want to update the packages. Default is TRUE.
165
166       dist_upgrade
167           Set to TRUE if you want to run a dist-upgrade if your distribution
168           supports it. Default is FALSE.
169
170   installed_packages
171       This function returns all installed packages and their version.
172
173        task "get-installed", "server1", sub {
174
175           for my $pkg (installed_packages()) {
176             say "name    : " . $pkg->{"name"};
177             say "  version: " . $pkg->{"version"};
178           }
179
180        };
181
182   is_installed
183       This function tests if $package is installed. Returns 1 if true. 0 if
184       false.
185
186        task "isinstalled", "server01", sub {
187          if( is_installed("rex") ) {
188            say "Rex is installed";
189          }
190          else {
191            say "Rex is not installed";
192          }
193        };
194
195   update_package_db
196       This function updates the local package database. For example, on
197       CentOS it will execute yum makecache.
198
199        task "update-pkg-db", "server1", "server2", sub {
200          update_package_db;
201          install package => "apache2";
202        };
203
204   repository($action, %data)
205       Add or remove a repository from the package manager.
206
207       For Debian: If you have no source repository, or if you don't want to
208       add it, just remove the source parameter.
209
210        task "add-repo", "server1", "server2", sub {
211          repository "add" => "repository-name",
212             url      => "http://rex.linux-files.org/debian/squeeze",
213             key_url  => "http://rex.linux-files.org/DPKG-GPG-KEY-REXIFY-REPO"
214             distro    => "squeeze",
215             repository => "rex",
216             source    => 1;
217        };
218
219       To specify a key from a file use key_file => '/tmp/mykeyfile'.
220
221       To use a keyserver use key_server and key_id.
222
223       For ALT Linux: If repository is unsigned, just remove the sign_key
224       parameter.
225
226        task "add-repo", "server1", "server2", sub {
227          repository "add" => "altlinux-sisyphus",
228             url      => "ftp://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus",
229             sign_key  => "alt",
230             arch     => "noarch, x86_64",
231             repository => "classic";
232        };
233
234       For CentOS, Mageia and SuSE only the name and the url are needed.
235
236        task "add-repo", "server1", "server2", sub {
237          repository add => "repository-name",
238             url => 'http://rex.linux-files.org/CentOS/$releasever/rex/$basearch/';
239
240        };
241
242       To remove a repository just delete it with its name.
243
244        task "rm-repo", "server1", sub {
245          repository remove => "repository-name";
246        };
247
248       You can also use one call to repository to add repositories on multiple
249       platforms:
250
251        task "add-repo", "server1", "server2", sub {
252         repository add => myrepo => {
253           Ubuntu => {
254             url => "http://foo.bar/repo",
255             distro => "precise",
256             repository => "foo",
257           },
258           Debian => {
259             url => "http://foo.bar/repo",
260             distro => "squeeze",
261             repository => "foo",
262           },
263           CentOS => {
264             url => "http://foo.bar/repo",
265           },
266         };
267        };
268
269   package_provider_for $os => $type;
270       To set another package provider as the default, use this function.
271
272        user "root";
273
274        group "db" => "db[01..10]";
275        package_provider_for SunOS => "blastwave";
276
277        task "prepare", group => "db", sub {
278           install package => "vim";
279        };
280
281       This example will install vim on every db server. If the server is a
282       Solaris (SunOS) it will use the blastwave Repositories.
283
284
285
286perl v5.28.0                      2017-03-01             Rex::Commands::Pkg(3)
Impressum