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

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

问题描述

使用 with_items 推荐答案

更新:最新的

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

  • with_关键字依赖于查找插件-甚至项都是查找.
  • loop关键字与with_list等效,是简单循环的最佳选择.
  • loop关键字将不接受字符串作为输入,请参阅确保列表输入以进行循环:查询还是查找.
  • 通常来说,从with_X迁移到循环中涵盖的with_ *的任何使用都可以更新为使用循环.
  • 将with_items更改为循环时要小心,因为with_items会执行隐式单级展平.您可能需要使用 用循环flatten(1)来匹配确切的结果.
  • The with_ keywords rely on Lookup Plugins - even items is a lookup.
  • The loop keyword is equivalent to with_list, and is the best choice for simple loops.
  • The loop keyword will not accept a string as input, see Ensuring list input for loop: query vs. lookup.
  • Generally speaking, any use of with_* covered in Migrating from with_X to loop can be updated to use loop.
  • Be careful when changing with_items to loop, as with_items performed implicit single-level flattening. You may need to use flatten(1) with loop to match the exact outcome.


旧答案

根据文档

在2.5 Ansible之前,主要使用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天全站免登陆