Skip to main content

fail

fail module

Fail the playbook execution with a custom message. This module is useful for implementing custom validation logic and stopping execution when certain conditions are not met.

Examples

- name: Fail with a simple message
fail:
msg: "This playbook requires root privileges"

- name: Conditional failure
fail:
msg: "Variable 'required_var' is not defined"
when: required_var is not defined

- name: Fail with templated message
fail:
msg: "Service {{ service_name }} is not running"
when: service_status != "running"

- name: Validation failure
fail:
msg: "Invalid configuration: port must be between 1 and 65535"
when: port < 1 or port > 65535

Note: The fail module will immediately stop playbook execution and display the specified message.

Module Capabilities

  • Has Revert: false
  • Provides Variables: None

Inputs

ParameterTypeDescriptionRequiredDefaultChoices
msgstringThe failure message to display when the module executes. Can include Jinja2 templating.falseFailed as requested from task

Outputs

No outputs.