Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rex - Mini-Einführung Frankfurt Perl-Community ...

Renee
June 04, 2016

Rex - Mini-Einführung Frankfurt Perl-Community Workshop 2016

Renee

June 04, 2016
Tweet

More Decks by Renee

Other Decks in Programming

Transcript

  1. Rex

  2. task uname_a => sub { my $result = run 'uname

    -a'; say "uname: $result"; };
  3. $ rex uname_a [2016-06-04 11:34:24] INFO - Running task uname_a

    on <local> uname: Linux perl-services 3.13.0-86-generic \ #131-Ubuntu SMP Thu May 12 23:33:13 UTC 2016 \ x86_64 x86_64 x86_64 GNU/Linux
  4. group fra_pw => qw/ perl-services.de frankfurt.pm /; task uname_a =>

    sub { my $result = run 'uname -a'; say "uname: $result"; };
  5. desc "Lasse uname laufen..."; task uname_a => sub { my

    $result = run 'uname -a'; say "uname: $result"; };
  6. user "root"; password "mypassword"; desc "Lasse uname laufen..."; task uname_a

    => sub { my $result = run 'uname -a'; say "uname: $result"; };
  7. user 'root'; private_key '/path/to/your/private.key'; public_key '/path/to/your/public.key'; password 'my_password'; key_auth; desc

    "Lasse uname laufen..."; task uname_a => sub { my $result = run 'uname -a'; say "uname: $result"; };
  8. task prepare => sub { pkg "apache2", ensure => "latest";

    service "apache2", ensure => "started"; };
  9. task prepare => sub { create_user "otrs" => home =>

    '/opt/otrs/', no_create_home => 1, %{ $params->{otrs_user} || {} }; };
  10. task prepare => sub { # download, unpack and link

    otrs if ( ! is_file '/tmp/otrs-' . $version . '.tar.gz' ) { my $source = "http://otrs/.../otrs-$version.tar.gz"; my $target = "/tmp/otrs-$version.tar.gz"; run "wget -O $target $source"; } };
  11. task prepare => sub { file "/opt/otrs-$version/Kernel/Config.pm", content => template(

    '@Config', db => { host => $params->{db}->{schema}->{host}, schema => $params->{db}->{schema}->{name}, user => $params->{db}->{user}->{name}, password => $params->{db}->{user}->{password}, dsn => $self->db_obj->dsn, }, config_pm => $params->{'config.pm'} || [], ), owner => "root", mode => 630; }; __DATA__ @Config $Self->{DatabaseHost} = '<%= $db->{host} %>'; $Self->{Database} = '<%= $db->{schema} %>'; $Self->{DatabaseUser} = '<%= $db->{user} %>';
  12. $ rex -e 'say `uname -a`' [2016-06-04 12:29:16] INFO -

    Running task eval-line on <local> Linux perl-services 3.13.0-86-generic #131-Ubuntu SMP \ Thu May 12 23:33:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  13. • Ähnlich wie CPAN-Module • Für alle möglichen Bereiche existieren

    Zusatzpakete • Werden mit „include“ eingebunden
  14. include qw/Rex::Database::MySQL::Admin/; set mysql => user => 'root'; desc "Get

    the timestamp when the users logged in for the last time"; task last_logged_in => sub { my $result = Rex::Database::MySQL::Admin::execute({ schema => 'otrs', sql => $sql, }); my @lines = split /\n/, $result; shift @lines; for my $line ( @lines ) { my ($user, $time) = split /\s+/, $line; say "$user → $time"; } });