【发布时间】:2016-11-30 16:48:24
【问题描述】:
鉴于此任务,特别是在 when 语句中,引用以下标记的方法是什么:
"tags": {
"Name": "volume1"
},
任务:
- name: Attach correct ebs volume to correct instance using tags
local_action:
module: ec2_vol
region: '{{ region }}'
instance: "{{ item.instance_ids[0] }}"
id: vol-1111111111111111
name: ebs-volume1
device_name: /dev/sdf
with_items: '{{ ec2.results }}'
when:
- item.instance_ids[0] is defined
- item.tagged_instances.tags.Name == "volume1"
我收到一条错误消息,说没有属性“标签”。
我似乎也无法在调试语句中正确引用它。
我认为它可能是这样的:
item.tagged_instances.tags == "名称": "volume1"
我应该用大括号吗??
谢谢!
尼克
【问题讨论】:
-
您可以随时
debug: var=item检查它的内容和可用属性。我怀疑tagged_instances会在那里。 -
在使用 debug: var=item 进行检查后,我认为一切正常,但后来我意识到项目的一个迭代没有 tagged_instances。谢谢!我只是在看什么是有效的,而不是调试中没有...
-
...我的调试中有一个 when 语句跳过了我的任务不是...再次感谢
-
原来你比我想象的更正确...tagged_instances[0] 是访问它下面的变量的真正答案,因为在调试输出中它有一个 [ 符号这意味着它是列表!
标签: amazon-web-services tags ansible