Ansible with_items vs 循环 [英] Ansible with_items vs loop

查看:31
本文介绍了Ansible with_items vs 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 with_items循环 in ansilbe?

What is the difference between using with_items vs loops in ansilbe?

推荐答案

更新:最新的文档 列出了如下差异

Update: The most recent Documentation lists down the differences as below

  • with_ 关键字依赖于查找插件 - 即使是项目也是查找.
  • loop 关键字等价于 with_list,是简单循环的最佳选择.
  • loop 关键字不接受字符串作为输入,请参阅确保循环的列表输入:查询与查找.
  • 一般来说,Migrating from with_X to loop 中介绍的 with_* 的任何使用都可以更新为 use loop.
  • 将 with_items 更改为循环时要小心,因为 with_items 执行隐式单级展平.您可能需要使用flatten(1) 与循环匹配确切的结果.

<小时>

旧答案

根据文档

Ansible 2.5 之前主要使用 with_ 关键字来创建循环,loop 关键字基本类似于 with_list.

Before 2.5 Ansible mainly used the with_ keywords to create loops, the loop keyword is basically analogous to with_list.

所以基本上它们几乎相同,只有较新的版本在其语法中使用了loop.从 2.7.12 版开始,两者都按预期工作,但为了将来的兼容性,鼓励使用 loop 关键字.

So basically they are pretty much the same, only the newer version uses loop in its syntax. And as of version 2.7.12 both work as expected but using the loop keyword is encouraged for future compatibility.

这篇关于Ansible with_items vs 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆