line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Rex::Group::Lookup::INI - read host names and groups from an INI style file |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
With this module you can define host groups in an INI style file. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Rex::Group::Lookup::INI; |
16
|
|
|
|
|
|
|
groups_file 'file.ini'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Rex::Group::Lookup::INI; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
17
|
use v5.12.5; |
|
1
|
|
|
|
|
4
|
|
25
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
6
|
use Rex -base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
require Exporter; |
32
|
1
|
|
|
1
|
|
8
|
use base qw(Rex::Exporter); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
80
|
|
33
|
1
|
|
|
1
|
|
8
|
use vars qw(@EXPORT); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
10
|
use Rex::Helper::INI; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
@EXPORT = qw(groups_file); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 groups_file($file) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
With this function you can read groups from INI style files. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
File example: |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# servers.ini |
46
|
|
|
|
|
|
|
[webservers] |
47
|
|
|
|
|
|
|
fe01 |
48
|
|
|
|
|
|
|
fe02 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
[backends] |
51
|
|
|
|
|
|
|
be[01..03] |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
It supports the same expressions as the L command. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Since 0.42, it also supports custom host properties if the L feature flag is enabled: |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# servers.ini |
58
|
|
|
|
|
|
|
[webservers] |
59
|
|
|
|
|
|
|
server01 user=root password=foob4r sudo=true services=apache,memcache |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Rexfile |
62
|
|
|
|
|
|
|
use Rex -feature => ['use_server_auth']; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
task 'list_services', group => 'webservers', sub { |
65
|
|
|
|
|
|
|
say connection->server->option('services'); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub groups_file { |
71
|
1
|
|
|
1
|
1
|
7
|
my ($file) = @_; |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
2
|
my $section; |
74
|
|
|
|
|
|
|
my %hash; |
75
|
|
|
|
|
|
|
|
76
|
1
|
50
|
|
|
|
51
|
open( my $INI, "<", "$file" ) || die "Can't open $file: $!\n"; |
77
|
1
|
|
|
|
|
91
|
my @lines = <$INI>; |
78
|
1
|
|
|
|
|
7
|
chomp @lines; |
79
|
1
|
|
|
|
|
11
|
close($INI); |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
8
|
my $hash = Rex::Helper::INI::parse(@lines); |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
1
|
for my $k ( keys %{$hash} ) { |
|
1
|
|
|
|
|
5
|
|
84
|
9
|
|
|
|
|
14
|
my @servers; |
85
|
9
|
|
|
|
|
10
|
for my $servername ( keys %{ $hash->{$k} } ) { |
|
9
|
|
|
|
|
26
|
|
86
|
25
|
|
|
|
|
37
|
my $add = {}; |
87
|
25
|
100
|
66
|
|
|
92
|
if ( exists $hash->{$k}->{$servername} |
88
|
|
|
|
|
|
|
&& ref $hash->{$k}->{$servername} eq "HASH" ) |
89
|
|
|
|
|
|
|
{ |
90
|
1
|
|
|
|
|
2
|
$add = $hash->{$k}->{$servername}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
25
|
|
|
|
|
32
|
my $obj = Rex::Group::Entry::Server->new( name => $servername, %{$add} ); |
|
25
|
|
|
|
|
92
|
|
94
|
25
|
|
|
|
|
54
|
push @servers, $obj; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
9
|
|
|
|
|
30
|
group( "$k" => @servers ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |