在打印调试时,从stdout对已注册变量进行可能的循环


?

队员们,

我的任务是从json_query输出stdoud_lines中提取主机。

然后,我遍历每个主机名,并在每个主机上执行ssh连接和shell命令。

最后,为了列出每个主机的输出,我调试出了每个主机的results.i _s.i。有没有一种方法可以在resultsi上循环,其中i=我的具有主机条目的动态变量?我想在调试时循环。有什么提示吗?

任务:"ssh并运行shell命令,手动列出每个主机结果“

      - name: "RAID mount check for fscache on GPU Nodes"
        shell: ssh -F {{ ssh_cfg_path.stdout }} {{ item.node_name }}.{{ ssh_host }} "df -kh /raid/"
        ignore_errors: no
        register: raid_info
        failed_when: raid_info.rc != 0
        with_items: "{{ gpu_nodes }}"

      - name: raid_info result
        debug:
          var: raid_info

      - name: raid_info results0_stdout_lines
        debug:
          var: raid_info.results[0].stdout_lines
      - name: raid_info results1_stdout_lines
        debug:
          var: raid_info.results[1].stdout_lines

输出:

    TASK [team-services-pre-install-checks : raid_info results0_stdout_lines] ****
    Friday 25 October 2019  17:03:07 +0000 (0:00:00.041)       0:00:25.292 ******** 
    ok: [localhost] => {
        "raid_info.results[0].stdout_lines": [
            "Filesystem      Size  Used Avail Use% Mounted on", 
            "/dev/sdb1       7.0T  175G  6.5T   3% /raid"
        ]
    }

    TASK [team-services-pre-install-checks : raid_info results1_stdout_lines] ****
    Friday 25 October 2019  17:03:07 +0000 (0:00:00.040)       0:00:25.333 ******** 
    ok: [localhost] => {
        "raid_info.results[1].stdout_lines": [
            "Filesystem      Size  Used Avail Use% Mounted on", 
            "/dev/sdb1       7.0T  176G  6.5T   3% /raid"
        ]
    }

下面的方法不起作用或列出任何输出。

      - name: raid_info results loop over all hosts output/result
        debug:
          var: raid_info.results[{{ item }}].stdout_lines
        with_items: "{{ raid_info }}"

我想我需要使用hostvars,但我是个新手,不知道该怎么做。

转载请注明出处:http://www.shenkehuoyun.com/article/20230526/1803886.html