FAILED! => {"msg": "The conditional check .. Unable to look up a name or access an attribute in template string

Need Ansible help on error. Same ansible module/task getting error in 1 environment and completely fine in another. Dunno what the causes are. Here’s the error:

fatal: [hostname.com]: FAILED! => {“msg”: “The conditional check ‘‘failed’ in prereq.stdout_lines’ failed. The error was: error while evaluating conditional (‘failed’ in prereq.stdout_lines): Unable to look up a name or access an attribute in template string ({% if ‘failed’ in prereq.stdout_lines %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like ‘-’: argument of type ‘StrictUndefined’ is not iterable”}

here’s task snippet:

  • name: Check for patch conflicts

shell: ./patch_command {{ patch_directory }}/{{ patchid }}

environment: “{{ env }}”

args:

chdir: “{{ patch_directory }}”

when: patchid != ‘nopatch’

register: prereq

failed_when: “‘failed’ in prereq.stdout_lines”