【发布时间】:2021-08-03 10:15:11
【问题描述】:
我正在尝试从不同的堆栈中获取 instance_id 的列表:
---
- hosts: localhost
vars:
stack_names:
- 'stacka'
- 'stackb'
- 'stackc'
tasks:
- name: "get cloudformation facts from stacks"
cloudformation_facts:
stack_name: "{{ item }}"
stack_resources: true
with_items: "{{ stack_names }}"
register: cf_tmp
- name: "Get list of instance_ids"
set_fact:
instance_ids: "{{ dict(cf_tmp.results | map(attribute=ansible_facts['cloudformation'][stack_name]['stack_resources']['instance'])) }}"
- debug:
msg: "{{ instance_ids }}"
但出现以下错误:
TASK [Get list of instance_ids] *************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'stack_name' is undefined
无论如何要解决这个问题?
谢谢!
【问题讨论】:
-
我在您的示例中的任何地方都没有看到
stack_name定义(如您的错误消息所报告的那样)。你的意思是'stack_name'?此外,应在表达式中引用整个属性名称。由于不是每个人都可以访问 cloudfotmatiin 进行测试,因此您应该举例说明寄存器事实和确切的预期结果。 -
@jackw11111,更改为 cloudformation_facts 会导致类似的错误,而不是“stack_name”,而是“错误是:“dict object”没有属性“cloudformation”。似乎两者都是单栈。
-
您的示例可能需要
stack_name,see this documentation 说stack_name是必需的。