调试无法在ansible游戏中与with_items一起使用

时间:2019-04-10 15:12:58

标签: ansible

在调试注册任务中的特定值时需要帮助。

  • 调试: 信息:“ {{item.stdout}}” with_items:path_result.results

这不起作用

{     “已更改”:错误,     “ path_result”:{         “ msg”:“所有项目已完成”,         “已更改”:是,         “结果”:[             {                 “ _ansible_parsed”:是的,                 “ stderr_lines”:[],                 “ _ansible_item_result”:是的,                 “ end”:“ 2019-04-10 14:55:18.726270”,                 “ _ansible_no_log”:否,                 “ _ansible_delegated_vars”:{                     “ ansible_delegated_host”:“ ”,                     “ ansible_host”:“ ”                 },                 “ cmd”:“ cat /tmp/abc.conf | grep苹果”,                 “ rc”:0,                 “ stdout”:“ fruit = apple”,                 “ item”:“ 。* ”,                 “ delta”:“ 0:00:00.021499”,                 “ stderr”:“”,                 “已更改”:是,                 “调用”:{                     “ module_args”:{                         “创建”:null,                         “可执行”:null,                         “ _uses_shell”:是的,                         “ _raw_params”:“ cat /tmp/abc.conf | grep苹果”,                         “删除”:null,                         “警告”:是的,                         “ chdir”:null,                         “ stdin”:null                     }                 },                 “ stdout_lines”:[                     “水果=苹果”                 ],                 “ start”:“ 2019-04-10 14:55:18.704771”,                 “ _ansible_ignore_errors”:null,                 “失败”:false             }         ]     },     “ _ansible_verbose_always”:是的,     “ _ansible_no_log”:否 }

“ stdout”:“ fruit = apple”我想调试此特定输出。

1 个答案:

答案 0 :(得分:0)

您似乎已register {@ {1}}获得了一场比赛的结果。该变量还具有register: path_result。这是我想你拥有的:

path_result

这是我认为您需要的:

- command: cat /tmp/abc.conf | grep apple
  register: path_result

- debug:
    msg: "{{ item.stdout }}"
  with_items: "{{ path_result.results }}"

请注意在- command: cat /tmp/abc.conf | grep apple register: path_result - debug: msg: "{{ item.stdout }}" with_items: "{{ path_result.path_result.results }}" 中添加的.path_result部分。