Skip to content

Navigation Menu

Sign in
Sign up

Batches with server groups #1540

rwp0 started this conversation in Ideas
Discussion options

Currently it is not possible to indicate hosts or groups for batches to run on within the batch definition.

batch 'run_pre_upgrade_tasks', group => 'testing_servers', qw(
 task1
 task2
 task3
);

This syntax could be useful to have.

You must be logged in to vote

Replies: 1 comment

Comment options

Currently it is not possible to indicate hosts or groups for batches to run on within the batch definition.

That's because a batch is not intended to be more than an ordered list of tasks to execute one by one sequentially. A task is a combination of code ("what to execute") and target ("where to execute").

The target needs to be specified either as part of the task definition ("default target" for the task), or given on the CLI as with -H (for hosts) and -G (for host groups) to force it.

If a sequence of tasks need to be codified with anything more than their ordering, I recommend creating another task which calls all the others as needed. For example:

task 'run_pre_upgrade_tasks', group => 'testing_servers', sub {
 # different styles are available to call other tasks, choose one or more according to the requirements
 do_task 'task1'; # run `task1` exactly as that is defined
 run_task 'task2'; # run `task2` as defined, optionally overriding its target and/or pass parameters
 task3(); # run `task3`, calling it as a function (and for example pass parameters to it)
 needs 'task4'; # depend on `task4` (more or less "run it with already established parameters and connection")
};

That's a very similar syntax as suggested initially, more flexible than a batch, and already works without developing/maintaining/supporting a new feature :)

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /