Team, I have output and am trying to fail/pass based on existence of a string in the json response that am getting. any hint?
- name: "Fetch all gpu/dgx nodes from clusters using K8s facts"
k8s_facts:
kubeconfig: $WORKSPACE
kind: Node
label_selectors:
- nodeType=gpu
verify_ssl: no
register: node_list
- debug:
var: node_list
- debug:
var: node_list | json_query(query)
vars:
query: 'resources[].{node_name: metadata.name, nodeType: metadata.labels.nodeType}'
failed_when: '"gpu" not in query.results'
TASK [2_k8s_validations : debug] ******************************************************************************************************************************************************************
ok: [target1] => {
"node_list | json_query(query)": [
{
"nodeType": "gpu",
"node_name": "dgx"
},
{
"nodeType": "gpu",
"node_name": "dgx"
}
]
}```
TASK [2_k8s_validations : debug] ****************************************************************************************************************************************************************** fatal: [target1]: FAILED! => {"msg": "The conditional check '\"gpu\" not in query.results' failed. The error was: error while evaluating conditional (\"gpu\" not in query.results): Unable to look up a name or access an attribute in template string ({% if \"gpu\" not in query.results %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like '-': argument of type 'AnsibleUndefined' is not iterable"}
PLAY RECAP ************************************************** target1 : ok=10 changed=5 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0