gpt4 book ai didi

dictionary - Ansible 从单独的文件填充字典值

转载 作者:行者123 更新时间:2023-12-03 07:45:57 25 4
gpt4 key购买 nike

我想使用 Ansible CloudFormation 模块在 AWS 上部署基础设施堆栈。所以,我用这个Ansible CloudFormation example一起工作。

在将参数传递到 AWS 模板的示例中,有一个类似的部分

args:
template_parameters:
KeyName: jmartin
DiskType: ephemeral
InstanceType: m1.small
ClusterSize: 3
register: stack

这里template_parameters是一个带有键和值的字典。喜欢

"template_parameters": {
"DiskType": "ephemeral",
"ClusterSize": "3",
"InstanceType": "m1.small",
"KeyName": "jmartin"
}

所以,现在我想从另一个文件填充字典值,我在其中创建键和值的简单列表。喜欢

args:
template_parameters:
- include: param_values.yml
register: stack

param_values.yml中将是这样的:

KeyName: jmartin
DiskType: ephemeral
InstanceType: m1.small
ClusterSize: 3

但这并没有从文件中加载值。相反,它包含作为列表。

"template_parameters": [
{
"include": "param_values.yml"
}
]

最终返回此错误:

"msg": "argument template_parameters is of type and we were unable to convert to dict"

有没有办法只加载文件的内容而不是将其作为字典值包含在内?

最佳答案

您需要使用ansible中的include_vars模块。

http://docs.ansible.com/ansible/include_vars_module.html

来自文档 ->

Loads variables from a YAML/JSON files dynamically from within a file or from a directory recursively during task runtime. 

关于dictionary - Ansible 从单独的文件填充字典值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43898789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com