diff --git a/ChangeLog b/ChangeLog index cbc3ffbff..230780543 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,8 +4,13 @@ Revision history for Rex [API CHANGES] [BUG FIXES] + - Fix warning about redundant arguments when using sync with key + authentication + - Fix setting distributor when versioned feature flags are active [DOCUMENTATION] + - Clarify sudo usage for multiple commands + - Clarify task hooks documentation [ENHANCEMENTS] @@ -14,6 +19,8 @@ Revision history for Rex [MINOR] [NEW FEATURES] + - Add new configuration option to control attaching default authentication + info to tasks [REVISION] diff --git a/README.md b/README.md index b85b0dce5..f215fcf2d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Rex, the friendly automation framework [![Build Status](https://travis-ci.org/RexOps/Rex.svg?branch=master)](https://travis-ci.org/RexOps/Rex) +# Rex, the friendly automation framework [![Build Status](https://travis-ci.com/RexOps/Rex.svg?branch=master)](https://travis-ci.com/RexOps/Rex) The main ideas behind Rex are: diff --git a/lib/Rex.pm b/lib/Rex.pm index a9202cfcb..1ba17f630 100644 --- a/lib/Rex.pm +++ b/lib/Rex.pm @@ -757,7 +757,7 @@ sub import { # remove default task auth if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.31 ) { Rex::Logger::debug("activating featureset >= 0.31"); - Rex::TaskList->create()->set_default_auth(0); + Rex::Config->set_default_auth(0); $found_feature = 1; } diff --git a/lib/Rex/Commands.pm b/lib/Rex/Commands.pm index eeec7c0cd..5a41b2278 100644 --- a/lib/Rex/Commands.pm +++ b/lib/Rex/Commands.pm @@ -1298,13 +1298,16 @@ sub get { =head2 before($task => sub {}) -Run code before executing the specified task. The special taskname 'ALL' can be used to run code before all tasks. +Run code before executing the specified task. + +The task name is a regular expression to find all tasks with a matching name. The special task name C<'ALL'> can also be used to run code before all tasks. + If called repeatedly, each sub will be appended to a list of 'before' functions. In this hook you can overwrite the server to which the task will connect to. The second argument is a reference to the server object that will be used for the connection. -Note: must come after the definition of the specified task +Please note, this must come after the definition of the specified task. before mytask => sub { my ($server, $server_ref, $cli_args) = @_; @@ -1327,10 +1330,13 @@ sub before { =head2 after($task => sub {}) -Run code after the task is finished. The special taskname 'ALL' can be used to run code after all tasks. +Run code after executing the specified task. + +The task name is a regular expression to find all tasks with a matching name. The special task name C<'ALL'> can be used to run code after all tasks. + If called repeatedly, each sub will be appended to a list of 'after' functions. -Note: must come after the definition of the specified task +Please note, this must come after the definition of the specified task. after mytask => sub { my ($server, $failed, $cli_args) = @_; @@ -1356,13 +1362,16 @@ sub after { =head2 around($task => sub {}) -Run code before and after the task is finished. The special taskname 'ALL' can be used to run code around all tasks. +Run code around the specified task (that is both before and after executing it). + +The task name is a regular expression to find all tasks with a matching name. The special task name C<'ALL'> can be used to run code around all tasks. + If called repeatedly, each sub will be appended to a list of 'around' functions. In this hook you can overwrite the server to which the task will connect to. The second argument is a reference to the server object that will be used for the connection. -Note: must come after the definition of the specified task +Please note, this must come after the definition of the specified task. around mytask => sub { my ($server, $server_ref, $cli_args, $position) = @_; @@ -1392,10 +1401,13 @@ sub around { =head2 before_task_start($task => sub {}) -Run code before executing the specified task. This gets executed only once for a task. The special taskname 'ALL' can be used to run code before all tasks. +Run code before executing the specified task. This gets executed only once for a task. + +The task name is a regular expression to find all tasks with a matching name. The special task name C<'ALL'> can be used to run code before all tasks. + If called repeatedly, each sub will be appended to a list of 'before_task_start' functions. -Note: must come after the definition of the specified task +Please note, this must come after the definition of the specified task. before_task_start mytask => sub { # do some things @@ -1417,10 +1429,13 @@ sub before_task_start { =head2 after_task_finished($task => sub {}) -Run code after the task is finished (and after the ssh connection is terminated). This gets executed only once for a task. The special taskname 'ALL' can be used to run code before all tasks. +Run code after the task is finished (and after the ssh connection is terminated). This gets executed only once for a task. + +The task name is a regular expression to find all tasks with a matching name. The special task name C<'ALL'> can be used to run code before all tasks. + If called repeatedly, each sub will be appended to a list of 'after_task_finished' functions. -Note: must come after the definition of the specified task +Please note, this must come after the definition of the specified task. after_task_finished mytask => sub { # do some things diff --git a/lib/Rex/Commands/Rsync.pm b/lib/Rex/Commands/Rsync.pm index 318f4142a..507548a59 100644 --- a/lib/Rex/Commands/Rsync.pm +++ b/lib/Rex/Commands/Rsync.pm @@ -235,10 +235,9 @@ sub sync { else { if ( $auth_type eq "key" ) { $cmd = sprintf( $cmd, - 'ssh -i ' + 'ssh -i ' . $server->get_private_key - . " -o StrictHostKeyChecking=no -p " . "$port", - $port ); + . " -o StrictHostKeyChecking=no -p $port" ); } else { $cmd = sprintf( $cmd, 'ssh -o StrictHostKeyChecking=no -p ' . "$port" ); diff --git a/lib/Rex/Commands/Run.pm b/lib/Rex/Commands/Run.pm index 5ff575408..4cc769eb1 100644 --- a/lib/Rex/Commands/Run.pm +++ b/lib/Rex/Commands/Run.pm @@ -386,13 +386,23 @@ To run only a specific command with sudo, use : # running a single command with sudo as different user, and `cd` to another directory too say sudo { command => 'id', user => 'different', cwd => '/home/different' }; -Passing an anonymous I to C allows for running the commands in the sub with sudo: +To run multiple commands with C, either use an anonymous code reference directly: sudo sub { service 'nginx' => 'restart'; say run 'id'; }; +or pass it via C (optionally along a different user): + + sudo { + command => sub { + say run 'id'; + say run 'pwd', cwd => '/home/different'; + }, + user => 'different', + }; + B that some users receive the error C. In this case you have to disable C for this user. You can do this in your sudoers file with the following code: diff --git a/lib/Rex/Config.pm b/lib/Rex/Config.pm index d5ba5c9ff..c8cbeea95 100644 --- a/lib/Rex/Config.pm +++ b/lib/Rex/Config.pm @@ -60,6 +60,7 @@ our ( $use_template_ng, $use_rex_kvm_agent, $autodie, $task_chaining_cmdline_args, $waitpid_blocking_sleep_time, $write_utf8_files, + $default_auth, ); # some defaults @@ -1591,6 +1592,27 @@ sub get_write_utf8_files { return $write_utf8_files; } +=head2 set_default_auth + +=head2 get_default_auth + +Sets and gets the value of the C<$default_auth> configuration variable. + +This controls whether Rex should attach default authentication info to tasks. + +Default is C<1>. + +=cut + +sub set_default_auth { + my $self = shift; + $default_auth = shift; +} + +sub get_default_auth { + return $default_auth // 1; +} + =head2 register_set_handler($handler_name, $code) Register a handler that gets called by I. diff --git a/lib/Rex/Interface/Fs/Local.pm b/lib/Rex/Interface/Fs/Local.pm index 161538635..4f7ffa71a 100644 --- a/lib/Rex/Interface/Fs/Local.pm +++ b/lib/Rex/Interface/Fs/Local.pm @@ -170,7 +170,7 @@ sub rename { else { ($old) = $self->_normalize_path($old); ($new) = $self->_normalize_path($new); - $exec->exec("/bin/mv $old $new"); + $exec->exec("/bin/mv -f $old $new"); } if ( $? == 0 ) { return 1; } diff --git a/lib/Rex/TaskList/Base.pm b/lib/Rex/TaskList/Base.pm index aaf776f16..2c83a91d0 100644 --- a/lib/Rex/TaskList/Base.pm +++ b/lib/Rex/TaskList/Base.pm @@ -35,7 +35,7 @@ sub new { bless( $self, $proto ); $self->{IN_TRANSACTION} = 0; - $self->{DEFAULT_AUTH} = 1; + $self->{DEFAULT_AUTH} = Rex::Config->get_default_auth(); $self->{tasks} = {}; return $self; diff --git a/t/group.t b/t/group.t index 5f6588566..3ff8affe4 100644 --- a/t/group.t +++ b/t/group.t @@ -4,6 +4,7 @@ use warnings; use Test::More tests => 95; use Rex -feature => '0.31'; +use Rex::Group; delete $ENV{REX_USER};