【问题标题】:Ansible populate dictionary values from separate fileAnsible 从单独的文件中填充字典值
【发布时间】:2017-05-15 16:27:22
【问题描述】:

我想使用 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": "参数 template_parameters 是类型,我们 无法转换为 dict"

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

【问题讨论】:

    标签: dictionary ansible amazon-cloudformation


    【解决方案1】:

    你需要在 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. 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-08
      • 2013-03-15
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多