| 1 | # | ||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||
| 3 | # | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Rex::Group::Lookup::File - read hostnames from a file. | ||||||||||
| 8 | |||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||
| 10 | |||||||||||
| 11 | With this module you can define hostgroups out of a file. | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | use Rex::Group::Lookup::File; | ||||||||||
| 16 | group "webserver" => lookup_file("./hosts.lst"); | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | =head1 EXPORTED FUNCTIONS | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | package Rex::Group::Lookup::File; | ||||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | use v5.14.4; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||
| 29 | |||||||||||
| 30 | 1 | require Exporter; | |||||||||
| 31 | 1 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 1 | ▶ | use vars qw(@EXPORT); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 1 | @EXPORT = qw(lookup_file); | |||||||||
| 35 | |||||||||||
| 36 | =head2 lookup_file($file) | ||||||||||
| 37 | |||||||||||
| 38 | With this function you can read hostnames from a file. Every hostname in one line. | ||||||||||
| 39 | |||||||||||
| 40 | group "webserver" => lookup_file("./webserver.lst"); | ||||||||||
| 41 | group "mailserver" => lookup_file("./mailserver.lst"); | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub lookup_file { | ||||||||
|
Subroutine
lookup_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 46 | 0 | my ($file) = @_; | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | open( my $fh, "<", $file ) or die($!); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | my @content = grep { !/^\s*$|^#/ } <$fh>; | |||||||||
| 50 | 0 | close($fh); | |||||||||
| 51 | |||||||||||
| 52 | 0 | chomp @content; | |||||||||
| 53 | |||||||||||
| 54 | 0 | return @content; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | 1; | |||||||||