将迭代值存储在ansible中

时间:2018-08-10 18:54:44

标签: ansible ansible-2.x

有没有办法打破ansible中的for循环? 我有一个非常具体的要求,我想知道哪个项目返回空的shell输出。 这里的问题是,如果300满足该条件,则循环不会在此处中断并停止,而是在列表中的每个项目上移动并记录其输出。

如果300满足条件,它应该还给我300。

name: "When apache-login exists but vhost.conf doesnt contain servername"
  shell: netstat -lnpt | grep {{ item }} | awk -F "LISTEN      " '{print $2}' | awk -F "/" '{print $1}'
  register: open_port
  with_items:
        - 300
        - 301
  when: open_port is not defined
- debug:
    var: open_port

输出

  

好:[cdlipewtgag15.es.ad.adp.com] => {       “ open_port”:{           “已更改”:是,           “ msg”:“所有项目已完成”,           “结果”:[               {                   “ _ansible_ignore_errors”:null,                   “ _ansible_item_result”:是的,                   “ _ansible_no_log”:否,                   “ _ansible_parsed”:是的,                   “已更改”:是,                   “ cmd”:“ netstat -lnpt | grep 300 | awk -F \” LISTEN \“'{print $ 2}'| awk -F \” / \“'{print $ 1}'”,                   “ delta”:“ 0:00:00.087166”,                   “ end”:“ 2018-08-10 14:41:45.787153”,                   “失败”:错误,                   “调用”:{                       “ module_args”:{                           “ _raw_params”:“ netstat -lnpt | grep 300 | awk -F \” LISTEN \“'{print $ 2}'| awk -F \” / \“'{print $ 1}'',,                           “ _uses_shell”:是的,                           “ chdir”:null,                           “创建”:null,                           “可执行”:null,                           “删除”:null,                           “ stdin”:null,                           “警告”:为true                       }                   },                   “项目”:300,                   “ rc”:0,                   “ start”:“ 2018-08-10 14:41:45.699987”,                   “ stderr”:“”,                   “ stderr_lines”:[],                   “ stdout”:“”,                   “ stdout_lines”:[]               },               {                   “ _ansible_ignore_errors”:null,                   “ _ansible_item_result”:是的,                   “ _ansible_no_log”:否,                   “已更改”:错误,                   “项目”:301,                   “ skip_reason”:“条件结果为假”,                   “已跳过”:正确               }           ]       }

0 个答案:

没有答案