【发布时间】:2019-10-02 20:03:26
【问题描述】:
团队, 不知何故无法弄清楚这是什么错误。我正在做一个多字符串搜索,并为每个未找到的字符串相应地失败。
- name: "Validate kubectl access and k8s node lables"
debug:
msg: "kubectl get nodes --show-labels -l nodeType={{item}}"
with_items:
- gpu
- cpu
- monitoring
register: k8s_labelsresponse
- debug:
var: k8s_labelsresponse.stdout
failed_when: '"nodeType=gpu" not in k8s_labelsresponse.stdout or "nodeType=cpu" not in k8s_labelsresponse.stdout or "nodeType=monitoring" not in k8s_labelsresponse.stdout'
输出:
TASK [Validate kubectl access and k8s node lables]
ok: [target1] => (item=gpu) => {
"msg": "kubectl get nodes --show-labels -l nodeType=gpu"
}
ok: [target1] => (item=cpu) => {
"msg": "kubectl get nodes --show-labels -l nodeType=cpu"
}
ok: [target1] => (item=monitoring) => {
"msg": "kubectl get nodes --show-labels -l nodeType=monitoring"
}
TASK [debug] **************************************************************************************************************************************************
fatal: [target1]: FAILED! => {"msg": "The conditional check '\"nodeType=gpu\" not in k8s_labelsresponse.stdout or \"nodeType=cpu\" not in k8s_labelsresponse.stdout or \"nodeType=monitoring\" not in k8s_labelsresponse.stdout' failed. The error was: error while evaluating conditional (\"nodeType=gpu\" not in k8s_labelsresponse.stdout or \"nodeType=cpu\" not in k8s_labelsresponse.stdout or \"nodeType=monitoring\" not in k8s_labelsresponse.stdout): Unable to look up a name or access an attribute in template string ({% if \"nodeType=gpu\" not in k8s_labelsresponse.stdout or \"nodeType=cpu\" not in k8s_labelsresponse.stdout or \"nodeType=monitoring\" not in k8s_labelsresponse.stdout %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like '-': argument of type 'AnsibleUndefined' is not iterable"}
【问题讨论】:
-
查看变量
debug: var=k8s_labelsresponse以了解可能要测试的内容。
标签: ansible ansible-2.x ansible-template