Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -14,6 +19,8 @@ Revision history for Rex
[MINOR]

[NEW FEATURES]
- Add new configuration option to control attaching default authentication
info to tasks

[REVISION]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
2 changes: 1 addition & 1 deletion lib/Rex.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
35 changes: 25 additions & 10 deletions lib/Rex/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) = @_;
Expand All @@ -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) = @_;
Expand All @@ -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) = @_;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/Rex/Commands/Rsync.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
12 changes: 11 additions & 1 deletion lib/Rex/Commands/Run.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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<coderef> to C<sudo> allows for running the commands in the sub with sudo:
To run multiple commands with C<sudo>, either use an anonymous code reference directly:

sudo sub {
service 'nginx' => 'restart';
say run 'id';
};

or pass it via C<command> (optionally along a different user):

sudo {
command => sub {
say run 'id';
say run 'pwd', cwd => '/home/different';
},
user => 'different',
};

B<Note> that some users receive the error C<sudo: sorry, you must have a tty
to run sudo>. In this case you have to disable C<requiretty> for this user.
You can do this in your sudoers file with the following code:
Expand Down
22 changes: 22 additions & 0 deletions lib/Rex/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<set>.
Expand Down
2 changes: 1 addition & 1 deletion lib/Rex/Interface/Fs/Local.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion lib/Rex/TaskList/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions t/group.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use warnings;
use Test::More tests => 95;

use Rex -feature => '0.31';
use Rex::Group;

delete $ENV{REX_USER};

Expand Down