团队,我的任务在json输出中运行良好,但我只想查找pod名称和名称空间,而不是输出整个pod json输出。因此,我正在使用debug来提取pod的名称,但不确定如何沿侧面名称空间提取所有pod的名称。
任何提示?我无法从这里理解:extracting a variable from json output then debug and register the outout with ansible
- name: "Get a list of all pods from any namespace" k8s_facts: kind: Pod namespace: webhook kubeconfig: $WORKSPACE verify_ssl: no register: pod_list - debug: var: pod_list - name: list names and namespaces debug: msg: "{{ pod_list.resources[0].metadata.name }}"
输出:
TASK [3_validations_on_ssh : list names and namespaces] ******************************************************************************************************************************* ok: [target1] => { "msg": "k8s-webhook-auth-xxxx1" }
寻找容器的样本输出片段如下:类似地,它在pod_lsit中继续用于其他容器
TASK [3_validations_on_ssh : debug] ***************************************************** ok: [target1] => { "pod_list": { "changed": false, "failed": false, "resources": [ { "apiVersion": "v1", "kind": "Pod", "metadata": { "creationTimestamp": "2019-10-11T18:44:04Z", "generateName": "k8s-webhook-auth-", "labels": { "app": "k8s-webhook-auth", "controller-revision-hash": "666c6cb69d", "pod-template-generation": "20", "release": "k8s-webhook-auth" }, "name": "k8s-webhook-auth-xxxx1", "namespace": "webhook", "ownerReferences": [ { "apiVersion": "apps/v1", "blockOwnerDeletion": true, "controller": true, "kind": "DaemonSet", "name": "k8s-webhook-auth", "uid": "1e9-8e9b-ac1f6b4ea082" } ], "resourceVersion": "47592900", "selfLink": "/api/v1/namespaces/webhook/pods/k8s-webhook-auth-5jx6w", "uid": "1e9-8e9b-ac1f6b4ea082" },
预期输出:
k8s-webhook-auth-xxxx1 webhook
k8s-webhook-auth-xxxx2 webhook
k8s-webhook-auth-xxxx3 webhook
[团队,我的任务在json输出中运行正常,但我只想查找pod名称和名称空间,而不是输出整个pod json输出。因此,我正在使用debug拉出pod的名称,但不提取...
我认为您需要一个循环来获取所需的确切输出,但这意味着它不会出现在单个“消息”中,而是每个窗格一个消息,例如: