ansible with_items 列表列表正在变平 [英] ansible with_items list of lists is flattening
问题描述
我正在尝试使用 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屋!