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

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

07b86e788c12e66f05d3bb7099aa1967?s=47 Renee
June 04, 2016

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

07b86e788c12e66f05d3bb7099aa1967?s=128

Renee

June 04, 2016
Tweet

Transcript

  1. Rex

  2. Rex rexify.org

  3. Automatisierung / Konfiguration von Aufgaben

  4. Automatisierung / Konfiguration von Aufgaben mit Perl!

  5. • OTRS-Demoinstanzen • Auswertungen von Servern holen • Upgrades •

    Deployment von Anwendungen
  6. • Tasks werden in Rexfile gespeichert • Start über rex

    <taskname>
  7. task uname_a => sub { my $result = run 'uname

    -a'; say "uname: $result"; };
  8. $ 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
  9. • Wenn kein Server angegeben ist, wird alles auf localhost

    ausgeführt
  10. $ rex -H perl-services.de uname_a

  11. • Server können gruppiert werden

  12. group fra_pw => qw/ perl-services.de frankfurt.pm /; task uname_a =>

    sub { my $result = run 'uname -a'; say "uname: $result"; };
  13. $ rex -G fra_pw uname_a

  14. • Beschreibungen für die Tasks

  15. desc "Lasse uname laufen..."; task uname_a => sub { my

    $result = run 'uname -a'; say "uname: $result"; };
  16. Auth

  17. user "root"; password "mypassword"; desc "Lasse uname laufen..."; task uname_a

    => sub { my $result = run 'uname -a'; say "uname: $result"; };
  18. 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"; };
  19. Beispiele

  20. task prepare => sub { pkg "apache2", ensure => "latest";

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

    '/opt/otrs/', no_create_home => 1, %{ $params->{otrs_user} || {} }; };
  22. 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"; } };
  23. 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} %>';
  24. $ 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
  25. Zusatzpakete

  26. • Ähnlich wie CPAN-Module • Für alle möglichen Bereiche existieren

    Zusatzpakete • Werden mit „include“ eingebunden
  27. $ rexify --use Rex::Database::MySQL

  28. 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"; } });