ansible - Ansible 条件检查失败
问题描述
需要 Ansible 帮助解决错误。相同的 ansible 模块/任务在 1 个环境中出错,在另一个环境中完全正常。不知道是什么原因。这是错误:
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 %}).
Make sure your variable name does not contain invalid characters like '-': argument of type 'StrictUndefined' is not iterable"
}
这是任务片段:
- 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"
解决方案
是否有可能 prereq 变量未定义或在您收到错误的环境中有一个空的 prereq.stdout_lines ?
你可以
- debug:
var: prereq
在那个环境中添加一个,然后在这里发布输出吗?