gpt4 book ai didi

Ansible with_items 与循环

转载 作者:行者123 更新时间:2023-12-02 17:17:00 25 4
gpt4 key购买 nike

使用with_items有什么区别与 loops在安西尔贝?

最佳答案

更新:最新的Documentation列出差异如下

  • 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.
<小时/>

旧答案

根据 docs ,

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 关键字以实现 future 的兼容性。

关于Ansible with_items 与循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com