寄存器var中的ansible循环,用于组中的所有项目以及每个项目的结果

时间:2019-12-16 18:43:19

标签: ansible ansible-2.x ansible-inventory ansible-facts

团队,我有以下任务在节点组下列出的每个节点上运行kubectl命令。

然后我已注册并失败了。但是我感觉它是基于单个节点而不是所有节点的输出和失败。我该如何实现?

      - name: "Validate LABEL on all Nodes in gpu_group"
        shell: kubectl describe node {{ item }} | grep dummyType=dummy
        register: nodes_info
        with_items: "{{ groups['kube-gpu-node'] }}"
        failed_when: nodes_info.rc !=0
        ignore_errors: yes

      - name: debug shell command register var
        debug:
          var: nodes_info

输出:

TASK [: Validate LABEL on all Nodes in gpu_group] **************************************************************************************************************************************************
Monday 16 December 2019  18:35:18 +0000 (0:00:00.146)       0:00:00.146 *******
changed: [localhost] => (item=node_gpu_1)

TASK [: debug shell command register var] ****************************************************************************************************************************************
Monday 16 December 2019  18:35:19 +0000 (0:00:01.170)       0:00:01.316 *******
ok: [localhost] => {
    "nodes_info": {
        "changed": true,
        "msg": "All items completed",
        "results": [
            {
                "ansible_loop_var": "item",
                "changed": true,
                "cmd": "kubectl describe node node_gpu_1 | grep dummyType=dummy",
                "delta": "0:00:00.705048",
                "end": "2019-12-16 18:35:19.272663",
                "failed": false,
                "failed_when_result": false,
                "invocation": {
                    "module_args": {
                        "_raw_params": "kubectl describe node node_gpu_1 | grep dummyType=dummy",
                        "_uses_shell": true,
                        "argv": null,
                        "chdir": null,
                        "creates": null,
                        "executable": null,
                        "removes": null,
                        "stdin": null,
                        "stdin_add_newline": true,
                        "strip_empty_ends": true,
                        "warn": true
                    }
                },
                "item": "node_gpu_1",
                "rc": 0,
                "start": "2019-12-16 18:35:18.567615",
                "stderr": "",
                "stderr_lines": [],
                "stdout": "                    dummyType=dummy",
                "stdout_lines": [
                    "                    dummyType=dummy"
                ]
            }
        ]
    }
}

预期输出: shell命令应该在组中列出的所有节点上运行,并列出所有节点成功或失败的输出

0 个答案:

没有答案