Rex::Config - Handles Rex configuration
use Rex::Config; # set a config option Rex::Config->set_exec_autodie(TRUE); # get value of a config option my $user = Rex::Config->get_user();
This module holds all configuration options for Rex, and also allows you to specify your own ones for your modules.
Please take a look at Rex::Commands first, which provides convenience wrappers for many of these options.
While it's possible to use the methods below to set a configuration option directly, their main intended purpose is to be used as internal plumbing, and to provide an escape hatch in case there are no better alternatives.
Sets and gets the value of the $autodie configuration variable.
$autodie
This controls whether Rex should die() if there's an error while executing file system commands that are supposed to change the contents.
die()
Default is undef.
undef
Sets and gets the value of the $use_net_openssh_if_present configuration variable.
$use_net_openssh_if_present
This controls whether Rex should use Net::OpenSSH for connections if that is available.
Sets and gets the value of the $use_rex_kvm_agent configuration variable.
$use_rex_kvm_agent
This controls whether Rex should setup and use a serial device for the experimental Rex KVM agent for managed VMs.
Sets and gets the value of the $use_template_ng configuration variable.
$use_template_ng
This controls whether Rex should use Rex::Template::NG to render templates.
Sets and gets the value of the $set_no_append configuration variable.
$set_no_append
This controls whether Rex should overwrite or append values of configuration options when using the set command.
Sets and gets the value of the $check_service_exists configuration variable.
$check_service_exists
This controls whether Rex should die() early if it is asked to manage a service that doesn't exist.
Sets and gets the value of the $register_cmdb_template configuration variable.
$register_cmdb_template
This controls whether Rex should make CMDB data available to be used in templates as variables.
Sets and gets the value of the $fallback_auth configuration variable.
$fallback_auth
This can be used to define an array of hash references, each of them containing authentication details to be tried during connection attempts when the directly specified ones fail.
Sets and gets the value of the $task_call_by_method configuration variable.
$task_call_by_method
This controls whether calling tasks as a method is allowed or not.
Sets and gets the value of the $disable_taskname_warning configuration variable.
$disable_taskname_warning
This controls whether Rex should show or suppress the warning message about task names that can not be used as Perl identifiers.
Sets and gets the value of the $task_chaining_cmdline_args configuration variable.
$task_chaining_cmdline_args
This controls whether Rex should parse task arguments on the command line per task, or should pass all arguments to all tasks.
Sets and gets the value of the $verbose_run configuration variable.
$verbose_run
This controls whether Rex should show verbose output about executed run commands. This means an error message if the command is not found, a warning message if the exit code indicates an error, and an informational message upon success.
Sets and gets the value of the $exec_autodie configuration variable.
$exec_autodie
This controls whether Rex should die() or not when the exit code of executed run command indicate an error.
Sets and gets the value of the $no_path_cleanup configuration variable.
$no_path_cleanup
This controls whether Rex should use either the default or the explicitly configured PATH settings (via path or set_path) when executing commands or not.
PATH
Sets and gets the value of the $source_profile configuration variable.
$source_profile
This controls whether Rex should source shell-specific profile files before executing commands.
Sets and gets the value of the $say_format configuration variable.
$say_format
This controls the output format of the built-in say command (see also sayformat).
say
Sets and gets the value of the $do_reporting configuration variable.
$do_reporting
This controls whether Rex should do reporting on executed resources where it is supported. This only affects the data structures returned internally.
Sets and gets the value of the $report_type configuration variable, which can also be controlled via the REX_REPORT_TYPE environment variable.
$report_type
REX_REPORT_TYPE
This selects the reporting type (format) Rex should use, e.g. 'YAML'.
'YAML'
Sets and gets the value of the $sleep_hack configuration variable.
$sleep_hack
This controls whether Rex should use or not an extra 10 ns long sleep after executed commands.
This might help working around an issue when Rex runs inside a KVM virtualized host and Net::SSH2/libssh2 is used to connect to another VM on the same hardware.
Sets and gets the value of the $cache_type configuration variable, which can also be controlled via the REX_CACHE_TYPE environment variable.
$cache_type
REX_CACHE_TYPE
This selects the cache type Rex should use, e.g. 'YAML'.
Default is 'Base'.
'Base'
Sets and gets the value of the $use_cache configuration variable.
$use_cache
This controls whether Rex should use caching or not for runtime information like CMDB contents, hardware and operating system information, or the shell type that is being used to execute commands on the managed endpoint.
Sets and gets the value of the $openssh_opt configuration variable, which holds a hash of the SSH configuration options used for the connection. See the ssh_config(5) man page for the available options.
$openssh_opt
Rex::Config->set_openssh_opt( $option => $value, );
There is a custom option named initialize_options specific to Rex, which can be used to pass a hash reference describing the constructor parameters for the underlying Net::OpenSSH object:
initialize_options
Rex::Config->set_openssh_opt( initialize_options => { $parameter => $value, } );
Sets and gets the value of the $sudo_without_locales configuration variable.
$sudo_without_locales
This controls whether Rex should execute sudo commands without setting any locales via the LC_ALL environment variable.
LC_ALL
Warning: if the locale is something else than C or en_US, then things will break!
C
en_US
Sets and gets the value of the $sudo_without_sh configuration variable.
$sudo_without_sh
This controls whether Rex should run sudo commands without sh. This might break things.
sh
Sets and gets the keys and values of the %executor_for configuration variable.
%executor_for
This sets the executor for a given file type when using the upload_and_run() function of Rex::Helper::Run module.
upload_and_run()
Default is:
( perl => 'perl', python => 'python', ruby => 'ruby', bash => 'bash', )
Sets and gets the value of the $tmp_dir configuration variable.
$tmp_dir
This controls which directory Rex should use for temporary files.
Default is determined by the following logic:
try to use what File::Spec->tmpdir would return on the managed endpoint
File::Spec->tmpdir
fall back to '/tmp'
'/tmp'
Sets and gets the value of the $path configuration variable.
$path
This controls which PATH Rex should use when executing commands via the Rex::Commands::Run module.
The value should be set as an array reference, and will be dereferenced as such before returned by get_path. The path command is a convenience wrapper for set_path, and accepts an array.
get_path
set_path
Default is
qw( /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin /usr/pkg/bin /usr/pkg/sbin )
Sets and gets the value of the $user configuration variable, which also can be set via the REX_USER environment variable.
$user
REX_USER
This controls which user Rex should use for authentication.
value of REX_USER environment variable
user set by user command
user running Rex
Sets and gets the value of the $password configuration variable, which also can be set via the REX_PASSWORD environment variable.
$password
REX_PASSWORD
This controls what password Rex should use for authentication or as passphrase when using private keys.
Sets and gets the value of the $port configuration variable.
$port
This controls which port Rex should connect to.
get_port accepts an optional server => $server argument to return the port setting for the given $server as optionally set in group files.
get_port
server => $server
port
$server
Sets and gets the value of the $sudo_password configuration variable, which can also be controlled via the REX_SUDO_PASSWORD environment variable.
$sudo_password
REX_SUDO_PASSWORD
This controls what sudo password Rex should use.
value of REX_SUDO_PASSWORD environment variable
sudo password set by the sudo_password command
password set by the password command
empty string ('')
''
Sets and gets the value of the $source_global_profile configuration variable.
$source_global_profile
This controls whether Rex should source /etc/profile before executing commands.
/etc/profile
Sets and gets the value of the $max_connect_fails configuration variable.
$max_connect_fails
This controls how many times Rex should retry to connect before giving up.
get_max_connect_fails accepts an optional server => $server argument to connectionattempts setting for the given $server as optionally set in group files.
get_max_connect_fails
connectionattempts
Sets and gets the value of the $proxy_command configuration variable.
$proxy_command
This controls the SSH ProxyCommand Rex should set for connections when Net::OpenSSH is used.
get_proxy_command accepts an optional server => $server argument to return the proxycommand setting for the given $server as optionally set in group files.
get_proxy_command
proxycommand
Sets and gets the value of the $timeout configuration variable.
$timeout
This controls how many seconds Rex should wait for connections to succeed when using SSH or Rex::Commands::Rsync.
get_timeout accepts an optional server => $server argument to return the connecttimeout setting for the given $server as optionally set in group files.
get_timeout
connecttimeout
Sets and gets the value of the $password_auth configuration variable, which can also be set by setting the REX_AUTH_TYPE environment variable to pass.
$password_auth
REX_AUTH_TYPE
pass
This controls whether Rex should use the password authentication method.
Sets and gets the value of the $key_auth configuration variable, which can also be set by setting the REX_AUTH_TYPE environment variable to key.
$key_auth
key
This controls whether Rex should use the key authentication method.
Sets and gets the value of the $krb5_auth configuration variable, which can also be set by setting the REX_AUTH_TYPE environment variable to krb5.
$krb5_auth
krb5
This controls whether Rex should use the Kerberos 5 authentication method.
Sets and gets the value of the $public_key configuration variable.
$public_key
This controls which public key Rex should use when using Net::SSH2 for connections.
Sets and gets the value of the $private_key configuration variable.
$private_key
This controls which private key Rex should use with Rex::Commands::Rsync or when using Net::SSH2 for connections.
Sets and gets the value of the $parallelism configuration variable.
$parallelism
This controls how many hosts Rex should connect to in parallel.
Default is 1.
1
Sets and gets the value of the $log_filename configuration variable.
$log_filename
This controls which file Rex should use for logging.
Sets and gets the value of the $log_facility configuration variable.
$log_facility
This controls which log facility Rex should use when logging to syslog.
Default is 'local0'.
'local0'
Sets and gets the value of the $environment configuration variable.
$environment
This controls which environment Rex should use.
Default is ''.
Sets and gets the value of the $distributor configuration variable.
$distributor
This controls which method Rex should use for distributing tasks for parallel execution.
Sets and gets the value of the $template_function configuration variable.
$template_function
This controls the function to be used for rendering templates. The value should be a subroutine reference that will be called with passing two scalar references as positional arguments: first is template content, second is template variables.
if Rex::Template::NG is loadable and use_template_ng is true, use that
fall back to Rex::Template otherwise
Sets and gets the value of the $no_tty configuration variable.
$no_tty
This controls whether Rex should request a terminal when using Net::SSH2 or allocate a pseudo-tty for the remote process when using Net::OpenSSH.
Sets and gets the value of the $allow_empty_groups configuration variable.
$allow_empty_groups
This controls whether Rex should allow empty groups of hosts or not.
Default is 0.
0
Sets and gets the value of the $use_server_auth configuration variable.
$use_server_auth
This controls whether Rex should use server-specific authentication information from group files.
Sets and gets the value of the $waitpid_blocking_sleep_time configuration variable.
$waitpid_blocking_sleep_time
This controls how many seconds Rex should sleep between checking forks.
Default is 0.1.
0.1
Sets and gets the value of the $write_utf8_files configuration variable.
$write_utf8_files
This controls whether Rex should force UTF-8 encoding when writing files.
UTF-8
Sets and gets the value of the $default_auth configuration variable.
$default_auth
This controls whether Rex should attach default authentication info to tasks.
Register a handler that gets called by set.
Rex::Config->register_set_handler("foo", sub { my ($value) = @_; print "The user set foo -> $value\n"; });
And now you can use this handler in your Rexfile like this:
set foo => "bar";
With this function it is possible to register own sections in the users config file ($HOME/.rex/config.yml).
$HOME/.rex/config.yml
Example:
Rex::Config->register_config_handler("foo", sub { my ($param) = @_; print "bar is: " . $param->{bar} . "\n"; });
And now the user can set this in his configuration file:
base: user: theuser password: thepassw0rd foo: bar: baz
To install Rex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rex
CPAN shell
perl -MCPAN -e shell install Rex
For more information on module installation, please visit the detailed CPAN module installation guide.