参数组的类型为"dict",我们无法转换为列表

rum*_*ums 6 ansible ansible-playbook

我正在尝试将一些常用的AWS任务分解为角色,这样我就可以在剧本中更灵活地使用它们,并且遇到意想不到的障碍.我无法想出这个:

这个游戏可以直接使用"group"直接在任务中定义为列表:

ec2:
 image: "{{image}}"
 region: "{{region}}"
 group: [ "ssh", "outbound" ]
 [... other stuff]
Run Code Online (Sandbox Code Playgroud)

但是如果我把游戏放在角色中并在'defaults/main.yml'文件中定义'groups',Ansible就会失败,如下所示:

groups: ["ssh", "outbound"]
Run Code Online (Sandbox Code Playgroud)

该剧现在看起来像这样:

ec2:
 image: "{{image}}"
 region: "{{region}}"
 group: "{{groups}}"
 [... other stuff]
Run Code Online (Sandbox Code Playgroud)

Ansible失败了这条消息,似乎认为我的变量是一个字典,而不是一个列表:

fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "argument group is of type <type 'dict'> and we were unable to convert to list"}
Run Code Online (Sandbox Code Playgroud)

我要么缺少明显的东西,要么遇到Ansible变量解析的限制.有人对此有任何见解吗?

udo*_*dan 6

groups是一个保留变量,一个魔术变量,用于保存dict中所有库存组,每个组项目包含该组的所有主机.

您的方法应该通过选择任何其他变量名称来工作.