From 9db58a8d56a34b612e29d24f37d06092f975bae4 Mon Sep 17 00:00:00 2001 From: vividsnow Date: Wed, 8 Apr 2020 17:01:42 +0300 Subject: [PATCH 01/10] doc: sudo for multiple commands as different user --- lib/Rex/Commands/Run.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Rex/Commands/Run.pm b/lib/Rex/Commands/Run.pm index 5ff575408..f3a168495 100644 --- a/lib/Rex/Commands/Run.pm +++ b/lib/Rex/Commands/Run.pm @@ -392,6 +392,11 @@ Passing an anonymous I to C allows for running the commands in th service 'nginx' => 'restart'; say run 'id'; }; + # or running multiple commands with sudo as different user + sudo { user => 'different', command => sub { + say run 'id'; + say run 'pwd', cwd => '/home/different'; + }}; B that some users receive the error C. In this case you have to disable C for this user. From 1ad832d0463cbcb21e026729dd0e4883d5d4250b Mon Sep 17 00:00:00 2001 From: Steve Dondley Date: Mon, 13 Apr 2020 10:02:48 -0400 Subject: [PATCH 02/10] fix redundant argument warning --- lib/Rex/Commands/Rsync.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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" ); From 0c7944e66218cd07309156834f54de04fb0665c8 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Wed, 15 Apr 2020 00:01:27 +0200 Subject: [PATCH 03/10] Clarify sudo usage for multiple commands --- ChangeLog | 1 + lib/Rex/Commands/Run.pm | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index cbc3ffbff..799ef61e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Revision history for Rex [BUG FIXES] [DOCUMENTATION] + - Clarify sudo usage for multiple commands [ENHANCEMENTS] diff --git a/lib/Rex/Commands/Run.pm b/lib/Rex/Commands/Run.pm index f3a168495..4cc769eb1 100644 --- a/lib/Rex/Commands/Run.pm +++ b/lib/Rex/Commands/Run.pm @@ -386,17 +386,22 @@ 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 running multiple commands with sudo as different user - sudo { user => 'different', command => sub { - say run 'id'; - say run 'pwd', cwd => '/home/different'; - }}; + +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. From b7de2a7574ffd1ebaa65a3e1bf4b8a31dc783cb7 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Wed, 15 Apr 2020 21:50:36 +0200 Subject: [PATCH 04/10] Update changelog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index cbc3ffbff..7cc3e66e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Revision history for Rex [API CHANGES] [BUG FIXES] + - Fix warning about redundant arguments when using sync with key + authentication [DOCUMENTATION] From 0990d9de4f3d5fe283e7a9bc7d54db32ba9ac3b9 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Mon, 13 Apr 2020 20:59:46 +0200 Subject: [PATCH 05/10] Update status badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 21da2a3592ff10f03288263062c38a68d73a3297 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Tue, 7 Apr 2020 19:55:48 +0200 Subject: [PATCH 06/10] Add configuration option to control default_auth --- ChangeLog | 2 ++ lib/Rex/Config.pm | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index f7bf3be94..e5e3d26bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,8 @@ Revision history for Rex [MINOR] [NEW FEATURES] + - Add new configuration option to control attaching default authentication + info to tasks [REVISION] 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. From 1c64be847760403aac27c04bd76abd7aa0a47335 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Tue, 7 Apr 2020 20:09:04 +0200 Subject: [PATCH 07/10] Replace hardcoded default with configuration option --- lib/Rex/TaskList/Base.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From e33d57d53e70fa5c35191343b9709a7d978c3bd5 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Tue, 7 Apr 2020 20:11:33 +0200 Subject: [PATCH 08/10] Avoid early instantiation of TaskList object (fix #1284) Rex::Group was loaded early through Rex::TaskList::Base for group tests, so that need to be imported explicitly now. --- ChangeLog | 1 + lib/Rex.pm | 2 +- t/group.t | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e5e3d26bc..0ac334ee1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Revision history for Rex [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 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/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}; From 018b654aa4606b070e450d9e27de6be0885e8718 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Sun, 12 Apr 2020 19:58:10 +0200 Subject: [PATCH 09/10] Clarify task hooks documentation --- ChangeLog | 1 + lib/Rex/Commands.pm | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ac334ee1..230780543 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ Revision history for Rex [DOCUMENTATION] - Clarify sudo usage for multiple commands + - Clarify task hooks documentation [ENHANCEMENTS] 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 From 637fa41d8056f0bab6001b6735d9fdd4ce6a676f Mon Sep 17 00:00:00 2001 From: Steve Dondley Date: Thu, 16 Apr 2020 00:30:48 -0400 Subject: [PATCH 10/10] prevent hanging when renaming file For https://github.com/RexOps/Rex/issues/1299 --- lib/Rex/Interface/Fs/Local.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; }