Skip to content

Commit d709f35

Browse files
authored
Merge branch 'master' into 1475_rex-built-in-template-modules
2 parents da8538c + 9663d7f commit d709f35

File tree

11 files changed

+384
-262
lines changed

11 files changed

+384
-262
lines changed

.github/workflows/build_and_test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ jobs:
4242
uses: actions/cache@v2
4343
with:
4444
path: local
45-
key: cache-build-modules-${{ env.OS_VERSION }}-${{ env.PERL_VERSION }}-${{ env.BUILD_TIMESTAMP }}
46-
restore-keys: cache-build-modules-${{ env.OS_VERSION }}-${{ env.PERL_VERSION }}-
45+
key: cache-build-modules-${{ secrets.CACHE_VERSION }}-${{ env.OS_VERSION }}-${{ env.PERL_VERSION }}-${{ env.BUILD_TIMESTAMP }}
46+
restore-keys: cache-build-modules-${{ secrets.CACHE_VERSION }}-${{ env.OS_VERSION }}-${{ env.PERL_VERSION }}-
4747
- name: Cache perlcritic history
4848
uses: actions/cache@v2
4949
with:
5050
path: /tmp/cache/.perlcritic-history
51-
key: cache-perlcritic-history-${{ env.BUILD_TIMESTAMP }}
52-
restore-keys: cache-perlcritic-history-
51+
key: cache-perlcritic-history-${{ secrets.CACHE_VERSION }}-${{ env.BUILD_TIMESTAMP }}
52+
restore-keys: cache-perlcritic-history-${{ secrets.CACHE_VERSION }}-
5353
- name: Log perl information
5454
run: perl -V
5555
- name: Install packages

CONTRIBUTING.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,20 @@ The first step of any change proposal is to open an issue about it. This gives a
3232

3333
To cover the vast majority of typical discussion points in advance, there are predefined templates for issues and pull requests. Please make sure to use them in order to streamline the workflow.
3434

35-
If something comes up that is not a good fit for the templates, that's probably already an early indicator that it should be discussed more closely. In this case please contact us first, or at least provide a reasoning about why the template had to be ignored in that specific case.
35+
If something comes up that is not a good fit for the templates, that's probably already an early indicator that it should be discussed more closely. In this case please [contact us](https://www.rexify.org/support/index.html) first, or at least provide a reasoning about why the template had to be ignored in that specific case.
36+
37+
### Rex core vs extending Rex
38+
39+
Strictly speaking the core competency of Rex is to execute commands, manage files, define tasks, and orchestrate their execution.
40+
41+
Rex gained lots of other capabilities over time, and historically many of them landed in core as well. But it is often possible to extend Rex by only minimally changing the core, if at all. For example this includes adding support to:
42+
43+
- manage new operating systems
44+
- new shell types
45+
- new virtualization methods
46+
- new cloud providers
47+
48+
It is highly encouraged to add such new capabilities via their own extension modules outside the core. If in doubt, please check some of the common scenarios below, or [contact us](https://www.rexify.org/support/index.html).
3649

3750
### Cross platform support
3851

@@ -183,6 +196,34 @@ It is generally recommended to:
183196
- [rebase](https://docs.github.com/en/github/using-git/about-git-rebase) your feature branch on top of the default branch if there are new commits since the feature branch has been created
184197
- use follow up/clean up commits on the same PR, but then please also [squash related commits](https://docs.github.com/en/github/using-git/about-git-rebase) together in the feature branch _before_ merging in order to keep a tidy history (in other words, no "tidy only" or "fix typo" commits are necessary)
185198

199+
## Common scenarios
200+
201+
### Add support to manage new operating systems
202+
203+
Allowing Rex to manage a new OS requires the following steps:
204+
205+
1. Teach rex about how to detect the given OS
206+
207+
- add a way to `Rex::Hardware::Host::get_operating_system()` to detect the given OS
208+
- add a new `is_myos()` function to `Rex::Commands::Gather`
209+
210+
1. Let Rex choose the proper package and service management modules for the given OS
211+
212+
- modify `Rex::Service` and `Rex::Pkg`
213+
214+
1. Add new service and package management modules specific to the given OS
215+
216+
- add `Rex::Service::MyOS`
217+
- add `Rex::Pkg::MyOS`
218+
219+
### Add support for new virtualization methods
220+
221+
Assuming the new virtualization method is called `MyVirt`, the following steps are required:
222+
223+
- create the top-level `Rex::Virtualization::MyVirt` module which includes the constructor, and the documentation
224+
- create submodules for each virtualization command, e.g. `Rex::Virtualization::MyVirt::info`
225+
- implement the logic of the given command as the `execute` method
226+
186227
## Contribute to this guide
187228

188229
If you think some of the information here is outdated, not clear enough, or have bugs, feel free to contribute to it too!

ChangeLog

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Revision history for Rex
44
[API CHANGES]
55

66
[BUG FIXES]
7-
- Remove unused tasks array
7+
- Detect invalid hostgroup expressions
88

99
[DOCUMENTATION]
10-
- Update support channels
1110

1211
[ENHANCEMENTS]
1312

@@ -19,6 +18,27 @@ Revision history for Rex
1918

2019
[REVISION]
2120

21+
1.13.4 2021-07-05 Ferenc Erki <[email protected]>
22+
[DOCUMENTATION]
23+
- Add section about Rex core vs extending Rex
24+
- Add common scenarios to contributing guide
25+
- Clarify documentation of run command
26+
- Clarify documentation of can_run command
27+
- Fix Rex::Task synopsis
28+
- Clarify documentation of rex script
29+
30+
1.13.3.2-TRIAL 2021-07-03 Ferenc Erki <[email protected]>
31+
[BUG FIXES]
32+
- Fix local file copy on Windows
33+
34+
1.13.3.1-TRIAL 2021-07-02 Ferenc Erki <[email protected]>
35+
[BUG FIXES]
36+
- Remove unused tasks array
37+
- Fix file hooks when source option is used
38+
39+
[DOCUMENTATION]
40+
- Update support channels
41+
2242
1.13.3 2021-03-05 Ferenc Erki <[email protected]>
2343
[BUG FIXES]
2444
- Fix parsing debconf values containing colons

bin/rex

Lines changed: 112 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -37,114 +37,149 @@ The C<rex> script can be used to execute tasks defined in a Rexfile from the com
3737

3838
=head1 SYNOPSIS
3939

40-
bash# rex -h # Show usage
41-
bash# rex -T # List tasks
42-
bash# rex uname # Run the 'uname' task
43-
bash# rex -H server[01..10] uname # Run the 'uname' task on all the specified hosts
44-
bash# rex -G production uname # Run 'uname' on hosts on the 'production' hostgroup
45-
bash# rex deploy --gracefully # Pass '--gracefully' to the 'deploy' task
40+
rex -h # Show usage
41+
rex -T # List tasks
42+
rex uname # Run the 'uname' task
43+
rex -H server[01..10] uname # Run the 'uname' task on all the specified hosts
44+
rex -G production uname # Run 'uname' on hosts on the 'production' hostgroup
45+
rex deploy --gracefully # Pass '--gracefully' to the 'deploy' task
4646

4747
=head1 USAGE
4848

49-
rex [<options>] [-H <host>] [-G <group>] <task> [<task-options>]
50-
rex -T[m|y|v] [<string>]
51-
52-
-b Run batch
53-
-e Run the given code fragment
54-
-E Execute a task on the given environment
55-
-G|-g Execute a task on the given server groups
56-
-H Execute a task on the given hosts (space delimited)
57-
-z Execute a task on hosts from this command's output
58-
59-
-K Public key file for the ssh connection
60-
-P Private key file for the ssh connection
61-
-p Password for the ssh connection
62-
-u Username for the ssh connection
63-
64-
-d Show debug output
65-
-ddd Show more debug output (includes profiling output)
66-
-m Monochrome output: no colors
67-
-o Output format
68-
-q Quiet mode: no log output
69-
-qw Quiet mode: only output warnings and errors
70-
-Q Really quiet: output nothing
71-
72-
-T List tasks
73-
-Ta List all tasks, including hidden
74-
-Tm List tasks in machine-readable format
75-
-Tv List tasks verbosely
76-
-Ty List tasks in YAML format
77-
78-
-c Turn cache ON
79-
-C Turn cache OFF
80-
-f Use this file instead of Rexfile
81-
-F Force: disregard lock file
82-
-h Display this help message
83-
-M Load this module instead of Rexfile
84-
-O Pass additional options, like CMDB path
85-
-s Use sudo for every command
86-
-S Password for sudo
87-
-t Number of threads to use (aka 'parallelism' param)
88-
-v Display (R)?ex version
49+
rex [<options>] [-H <host>] [-G <group>] <task> [<task-options>]
50+
rex -T[m|y|v] [<string>]
51+
52+
-b Run batch
53+
-e Run the given code fragment
54+
-E Execute a task on the given environment
55+
-G|-g Execute a task on the given server groups
56+
-H Execute a task on the given hosts (space delimited)
57+
-z Execute a task on hosts from this command's output
58+
59+
-K Public key file for the ssh connection
60+
-P Private key file for the ssh connection
61+
-p Password for the ssh connection
62+
-u Username for the ssh connection
63+
64+
-d Show debug output
65+
-ddd Show more debug output (includes profiling output)
66+
-m Monochrome output: no colors
67+
-o Output format
68+
-q Quiet mode: no log output
69+
-qw Quiet mode: only output warnings and errors
70+
-Q Really quiet: output nothing
71+
72+
-T List tasks
73+
-Ta List all tasks, including hidden
74+
-Tm List tasks in machine-readable format
75+
-Tv List tasks verbosely
76+
-Ty List tasks in YAML format
77+
78+
-c Turn cache ON
79+
-C Turn cache OFF
80+
-f Use this file instead of Rexfile
81+
-F Force: disregard lock file
82+
-h Display this help message
83+
-M Load this module instead of Rexfile
84+
-O Pass additional options, like CMDB path
85+
-s Use sudo for every command
86+
-S Password for sudo
87+
-t Number of threads to use (aka 'parallelism' param)
88+
-v Display (R)?ex version
8989

9090
=head1 Rexfile
9191

9292
When you run C<rex> it reads the file C<Rexfile> in the current working
93-
directory. A Rexfile consists of 2 major parts: Configuration and Task
94-
Definitions.
93+
directory. A Rexfile consists of 2 major parts: configuration and task
94+
definitions.
9595

9696
=head2 Configuration
9797

98-
=head3 Simple Authentication
98+
See all the available commands in L<Rex::Commands>.
9999

100-
user "bruce";
101-
password "batman";
102-
pass_auth;
100+
=head3 Simple authentication
103101

104-
=head3 Key Authentication
102+
user 'bruce';
103+
password 'batman';
104+
pass_auth;
105105

106-
private_key "/path/to/your/private/key.file";
107-
public_key "/path/to/your/public/key.file";
106+
=head3 Key authentication
108107

109-
=head3 Define Logging
108+
private_key '/path/to/your/private/key.file';
109+
public_key '/path/to/your/public/key.file';
110+
key_auth;
110111

111-
logging to_file => "rex.log";
112-
logging to_syslog => "local0";
112+
=head3 Define logging
113+
114+
logging to_file => 'rex.log';
115+
logging to_syslog => 'local0';
113116

114117
=head3 Group your servers
115118

116119
Rex gives you the ability to define groups of servers. Groups can be defined the Rexfile:
117120

118-
group "frontends" => "frontend01", "frontend02", "frontend03", "frontend04", "frontend[05..09]";
121+
group 'frontends' => 'frontend01', 'frontend02', 'frontend[03..09]';
122+
123+
Groups can also be defined in separate files, like C<server.ini>:
124+
125+
# server.ini
126+
[frontends]
127+
frontend[01..04]
119128

120-
Groups can also be defined in a B<server.ini> file:
129+
# Rexfile
130+
use Rex::Group::Lookup::INI;
131+
groups_file 'file.ini'
121132

122-
[frontends]
123-
frontend[01..04]
133+
See L<Rex::Group::Lookup::INI> for more details, and check the C<Rex::Group::Lookup> namespace for other formats.
124134

125-
=head2 Other Configuration
135+
=head2 Other configuration
126136

127-
timeout 10; # ssh timeout
128-
parallelism 2; # execute tasks in parallel
137+
timeout 10; # ssh timeout
138+
parallelism 2; # execute tasks in parallel
129139

130140
=head2 Defining tasks
131141

132142
A basic task looks like this:
133143

134-
# task description
135-
desc "This task tells you how long since the server was rebooted";
136-
137-
# task definition
138-
task "shortname", sub {
139-
say run "uptime";
140-
};
144+
# task description
145+
desc 'This task tells you how long since the server was rebooted';
146+
147+
# task definition
148+
task 'shortname', sub {
149+
say run 'uptime';
150+
};
151+
152+
By default it will be targeted at the same host where `rex` is being executed.
153+
154+
You can also set a default server as the task's target:
155+
156+
desc 'This is a long description of a task';
157+
task 'shortname',
158+
'frontend01',
159+
sub {
160+
say run 'uptime';
161+
};
162+
163+
or even a default server group:
164+
165+
desc 'This is a long description of a task';
166+
task 'shortname',
167+
group => 'frontends',
168+
sub {
169+
say run 'uptime';
170+
};
171+
172+
The task options from the command line will be passed to the task as well:
141173

142-
You can also set a default server group:
174+
# Rexfile
175+
desc 'Get task options';
176+
task 'get_task_options', sub {
177+
my $task_options = shift;
178+
my $option1 = $task_options->{option1};
179+
};
143180

144-
desc "This is a long description of a task";
145-
task "shortname", group => "frontends", sub {
146-
say run "uptime";
147-
};
181+
# command line
182+
rex get_task_options --option1=yes
148183

149184
=head1 TAB COMPLETION
150185

lib/Rex/Commands.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,9 +1786,12 @@ sub evaluate_hostname {
17861786
if ( $rule =~ m/,/ ) {
17871787
@ret = _evaluate_hostname_list( $start, $rule, $end );
17881788
}
1789-
else {
1789+
elsif ( $rule =~ m/[.]{2}/msx ) {
17901790
@ret = _evaluate_hostname_range( $start, $rule, $end );
17911791
}
1792+
else {
1793+
croak('Invalid hostgroup expression');
1794+
}
17921795

17931796
return @ret;
17941797
}

0 commit comments

Comments
 (0)