ansible with_items列表列表变平 [英] ansible with_items list of lists is flattening
本文介绍了ansible with_items列表列表变平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用ansible遍历列表列表以安装一些软件包.但是{{item}}返回的是子列表中的每个元素,而不是子列表本身.我有一个yaml文件,来自外部ansible的清单清单,它看起来像这样:
I'm trying to use ansible to loop over a list of lists to install some packages. But {{item}} is returning every element in the sub lists rather than the sublist itself. I have a yaml file which come from a manifest list from outside ansible and it looks like this:
---
modules:
- ['module','version','extra']
- ['module2','version','extra']
- ['module3','version','extra']
我的任务如下:
task:
- include_vars: /path/to/external/file.yml
- name: install modules
yum: name={{item.0}} state=installed
with_items: "{{ modules }}"
我跑步时得到:
fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR! int object has no element 0"}
当我尝试时:
- debug: msg="{{item}}"
with_items: "{{module}}"
它打印每个元素(模块,版本,其他内容等),而不仅仅是子列表(这是我期望的)
it prints every element (module, version, extra, and so on), not just the sublist (which is what I would expect)
推荐答案
不幸的是,这是预期的行为.请参见关于with_tems和嵌套列表的讨论
Unfortunately, this is the intended behavior. Please see this discussion on with_tems and nested lists
这篇关于ansible with_items列表列表变平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文