Команда, у меня есть ниже задача, которая перечисляет выходные данные, и я хочу написать условие fail_when, когда любой из хостов не показывает эту метку, задача завершится неудачей. ? Я хочу выполнить задачу, когда «nodeType»: «cpu» не присутствует ни на одном из хостов.
#Pull all cpu nodes by class label then check if that node has nodeType label
- name: "Fetch all CPU nodes from clusters using K8s beta.kubernetes.io/instance-type"
k8s_facts:
kind: Node
label_selectors:
- "beta.kubernetes.io/instance-type=f1.8xlarge"
verify_ssl: no
register: cpu_class_list
failed_when: cpu_class_list == ''
- debug:
var: cpu_class_list | json_query(query)
vars:
query: 'resources[].{node_name: metadata.name, nodeType: metadata.labels.nodeType, instanceType: metadata.labels."beta.kubernetes.io/instance-type"}'
TASK [3_validations_on_ssh : Fetch all CPU nodes from clusters using K8s beta.kubernetes.io/instance-type] ************************************************************************************
ok: [localhost]
TASK [3_validations_on_ssh : debug] ***********************************************************************************************************************************************************
ok: [localhost] => {
"cpu_class_list | json_query(query)": [
{
"instanceType": "f1.8xlarge",
"nodeType": "cpu",
"node_name": "hostA"
},
{
"instanceType": "f1.8xlarge",
"nodeType": "cpu",
"node_name": "hostB"
}
]
}