将ansible输出存储到变量

时间:2017-08-14 15:27:26

标签: amazon-ec2 ansible

我想使用Ansible来获取有关AWS Ec2实例的信息。我真的在寻找它的Instance-ID。我将使用它来遍历模板。但我似乎无法获得实例ID。以下是我到目前为止的情况:

val id: UUID = // other logic that looks this up
df.filter(s"id = $id")
df.filter("id = " convertToByteArray(id))
df.filter("id = " convertToHexString(id))

我知道这是不正确的,因为当我运行时,我得到:

  

“instanceId.instances.id”:“VARIABLE IS NOT NOTFINED!”

有人可以告诉我一种返回instanceId的方法吗?

1 个答案:

答案 0 :(得分:1)

如果您是第一次做某事,请逐步进行...了解内部情况。像:

- debug: var=instanceId
# to see raw result and find out that `instances` is there

- debug: var=instanceId.instances
# to see what `instanses` is, and to see it is a list

- debug: var=instanceId.instances[0]
# to see the first element of the list and see it's properties

- debug: var=instanceId.instances[0].id
# to see instance ID