amazon-web-services - 如何在字典列表中使用 set_fact?
问题描述
我有一个 ansible 脚本,它使用 ec2_instance_info 获取有关 EC2 实例的信息。它以字典列表的形式出现,如果其中不存在,我正在尝试为该列表中的每个项目添加一个字典值。如何让 set_fact 对每个字典执行操作?
我正在尝试完成的示例:
- name: Insert value if nonexistent
set_fact:
"{{item}}": "{{[item]|combine(add_val)}}"
when: item.public_ip_address is not defined
with_items: "{{info}}"
register: tmp_info
这导致:
... virtualization_type': 'hvm', 'cpu_options': {'core_count': 1, 'threads_per_core': 1}, 'capacity_reservation_specification': {'cap
acity_reservation_preference': 'open'}, 'hibernation_options': {'configured': False}, 'metadata_options': {'state': 'applied', 'http_tokens': 'optional', 'http_put_response_hop_limit': 1, 'http_endpoint': 'enabl
ed'}, 'enclave_options': {'enabled': False}}' is not valid. Variables must start with a letter or underscore character, and contain only letters, numbers and underscores."}
据我所知,它正在尝试获取 dict 的值并将其设置为名称。
有什么办法可以重写它以引用我要修改的有问题的字典,然后在同一个字典列表中修改它?
解决方案
推荐阅读
- flutter - Flutter SharedPreferences如何加载所有保存的?
- java - 如果用户达到字符限制,Android Studio 会抛出错误
- r - 将 SQL 凭据传递给 shinyproxy 应用程序
- string - 如何在python中连接字符串
- aws-lambda - 无法确定 AWS Lambda 无服务器函数的事件类型
- php - 模拟或存根 php 父类中的方法
- angular - Angular Universal FULL SSR + 路由器不进行 Http 调用
- java - 从 CompletableFuture 捕获未捕获的异常
- bash - 用于捕获 #(哈希)字符的 Bash 测试
- paypal - Paypal 集成,实时支付时出错