[Feature request] Run Command: successAndContinue value for onFailure input
- Dominant language
- Go
- Stars
- 1.2k
- Forks
- 357
- PR merge metrics
- No merged PRs in 30d
Description
As of [3.0.502.0](https://github.com/aws/amazon-ssm-agent/releases/tag/3.0.502.0), SSM Agent supports [shared inputs](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-plugins.html#shared-inputs) for all plugins that facilitate low-level conditional logic. However, a common if-else workflow does not seem straightforward with the current available values for `onFailure`.
For example, in a configuration management scenario, I have two separate Linux shell scripts. The first script (`verify`) checks a set of conditions and exits non-zero if any condition is not met. The second script (`apply`) makes changes to the system such that all conditions are now met. In this scenario, I want to invoke `apply` only if `verify` fails, but I do not want `verify`'s failure to affect the status of the overall execution. Here is the equivalent if-else logic in shell:
```sh
if ! ./verify; then ./apply; fi
# apply's exit status determines overall success or failure, not verify's.
```
Here is a partial document that conditionally invokes `apply` but also considers the entire command failed when `verify` fails:
```yaml
mainSteps:
- action: aws:runShellScript
inputs:
onSuccess: exit # Overall status will be Failed if this step fails.
runCommand:
- '#!/bin/sh'
- '$(exit 1)' # Change to 0 and the command skips apply.
name: verify
- action: aws:runShellScript
inputs:
runCommand:
- '#!/bin/sh'
- 'echo "apply ran"'
name: apply
```
In order both conditionally to invoke `apply` and to have `verify` not affect the overall command status, you have to invert `verify`'s exit status and use `successAndExit` for `onFailure`:
```yaml
mainSteps:
- action: aws:runShellScript
inputs:
onFailure: successAndExit # Overall status not affected by this step.
runCommand:
- '#!/bin/sh'
- '! $(exit 0)' # Change to 1 and the command skips apply.
name: verify
- action: aws:runShellScript
inputs:
runCommand:
- '#!/bin/sh'
- 'echo "apply ran"'
name: apply
```
If `onFailure` supported a `successAndContinue` value that could be used in conjunction with `onSuccess`, the above inverted logic would not be necessary:
```yaml
mainSteps:
- action: aws:runShellScript
inputs:
onFailure: successAndContinue # Overall status not affected by this step.
onSuccess: exit
runCommand:
- '#!/bin/sh'
- '$(exit 1)' # Change to 0 and the command skips apply.
name: verify
- action: aws:runShellScript
inputs:
runCommand:
- '#!/bin/sh'
- 'echo "apply ran"'
name: apply
```
Alternatively, a more generic feature might be a `critical` Boolean property for steps (similar to [Automation's isCritical](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-actions.html#automation-common)):
```yaml
mainSteps:
- action: aws:runShellScript
critical: false # Overall status not affected by this step.
inputs:
onSuccess: exit
runCommand:
- '#!/bin/sh'
- '$(exit 1)' # Change to 0 and the command skips apply.
name: verify
- action: aws:runShellScript
inputs:
runCommand:
- '#!/bin/sh'
- 'echo "apply ran"'
name: apply
```
Contributor guide
Research direction
Start by locating the SSM Agent entry points that parse and handle the onFailure and onSuccess inputs for aws:runShellScript, then compare their behavior with the shared-inputs documentation linked in the issue. Define how successAndContinue or critical: false should affect step and overall execution status, and add coverage for both successful and failing verify commands before confirming the conditional apply step behaves as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, shell
- Domain
- devops
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100