Skip to content

Commit

Permalink
Add option to fail, if remote cmd fails
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed Apr 14, 2020
1 parent 9fbec9c commit de2b550
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/ceres.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ The *instances* modules interacts with instances in the environment selected by
--no-progress-bar
: Do not show progress bar during command execution. This is useful for non-interactive sessions.

--fail-on-fail
: Exits with code != 1 if any remote command fails

-p, --public-ip
: Use public IP address of instance

Expand Down
3 changes: 3 additions & 0 deletions docs/man1/ceres.1
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ Sets remote login name
Do not show progress bar during command execution.
This is useful for non-interactive sessions.
.TP
.B \[en]fail-on-fail
Exits with code != 1 if any remote command fails
.TP
.B -p, \[en]public-ip
Use public IP address of instance
.TP
Expand Down
10 changes: 10 additions & 0 deletions src/modules/instances/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ impl Module for SubModule {
.long("no-progress-bar")
.help("Do not show progressbar during command execution"),
)
.arg(
Arg::with_name("fail-on-fail")
.long("fail-on-fail")
.help("Exits with code != 1 if any remote command fails"),
)
.arg(
Arg::with_name("public-ip")
.short("p")
Expand Down Expand Up @@ -106,6 +111,7 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
);

let progress_bar = !args.is_present("no-progress-bar");
let fail_on_fail = args.is_present("fail-on-fail");

let show_all = args.is_present("show-all");
let output_type = args.value_of("output").unwrap() // Safe
Expand All @@ -127,6 +133,10 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
run::output_results(output_type, show_all, results.as_slice())
.chain_err(|| ErrorKind::ModuleFailed(NAME.to_owned()))?;

if fail_on_fail && results.iter().any(|r| !r.exit_status.success()) {
return Err(Error::from_kind(ErrorKind::ModuleFailed(NAME.to_owned())));
}

Ok(())
}

Expand Down

0 comments on commit de2b550

Please sign in to comment.