# Passing condition to "failed\_when" as a variable

**URL:** <https://forum.ansible.com/t/passing-condition-to-failed-when-as-a-variable/45531>\
**Category:** Get Help\
**Created:** [March 15, 2026, 2:56pm UTC](https://forum.ansible.com/t/passing-condition-to-failed-when-as-a-variable/45531 "2026-03-15T14:56:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gundalow](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gundalow/32/99_2.png) [@gundalow](https://forum.ansible.com/u/gundalow)\
**Post date:** [March 15, 2026, 2:58pm UTC](https://forum.ansible.com/t/passing-condition-to-failed-when-as-a-variable/45531/2 "2026-03-15T14:58:56Z")

</div>

@Openuser87 welcome to the Ansible Forum!  
If you could copy in more of your playbook that would help.

Welcome to the Ansible Forum, let’s continue the discussion in

> [@Passing condition to "failed\_when" as a variable](https://forum.ansible.com/t/passing-condition-to-failed-when-as-a-variable/45530):
>
> I try to pass a condition to failed\_when as a variable in a role: my-role/defaults/main.yml: # list of commands to execute in form [command, changed\_when, failed\_when] my\_commands: - ["myapp init", "cmd\_result.rc == 0", "(cmd\_result.rc != 0) and ('Non-critical error' not in cmd\_result.stdout) and ('Non-critical error' not in cmd\_result.stderr)"] - [...] This would allow me to loop through the command list with custom changed\_when and failed\_when conditions: my-role/tasks/main.yml: - na…

---

_[View the full topic](https://forum.ansible.com/t/passing-condition-to-failed-when-as-a-variable/45531)._
