【问题标题】:google deployment manager, can you import files in jinja template that you call directly with --template?谷歌部署管理器,你可以在你直接用--template调用的jinja模板中导入文件吗?
【发布时间】:2019-10-10 09:36:40
【问题描述】:

https://cloud.google.com/deployment-manager/docs/configuration/templates/create-basic-template

我可以像这样直接部署模板:gcloud deployment-manager deployments create a-single-vm --template vm_template.jinja

但是,如果该模板依赖于需要导入的其他文件怎么办?如果使用 --config 文件,您可以在该文件中定义导入并将模板作为资源调用。但是您不能将参数/属性传递给配置文件。我想直接调用模板通过命令行传递--properties,但该模板还需要导入其他文件。

编辑:我需要的是顶级 jinja 模板而不是配置。我的困惑是你不能在没有模式文件的 jinja 模板中使用导入——它失败了,我认为它不受支持。所以解决方案只是用 jinja 模板(带有模式文件)交换配置,然后我可以使用 --properies

【问题讨论】:

    标签: google-deployment-manager


    【解决方案1】:

    也许您可以尝试将 importing the dependent files 放入您的配置文件中,如下所示:

    imports:
    - path: vm-template.jinja
    - path: vm-template-2.jinja
    
    # In the resources section below, the properties of the resources are replaced
    # with the names of the templates.
    
    resources:
    - name: vm-1
      type: vm-template.jinja
    - name: vm-2
      type: vm-template-2.jinja
    

    Set Arbitrary Metadata 来创建一个特殊变量,您可以将其传递并可能在 Deployment Manager 之外的其他应用程序中使用:

    properties:
      size:
        type: integer
        default: 2
        description: Number of Mongo Slaves
        variable-x: ultra-secret-sauce
    
    • 更多关于gcloud deployment-manager deployments create可选标志和示例的信息可以找到here.
    • 有关使用 Schema 传递属性的更多信息,请访问 here

    希望对你有帮助

    【讨论】:

    • hmm 可能会误解你,但不确定这是否能解决我的问题。真正的问题是无法通过命令行传递--properties 或覆盖顶级config 的任意值。我可以使用模板来做到这一点,但不能使用导入文件和模板的 yaml 配置。我不得不使用 makefile/sed 来转换我的配置——这感觉很傻。 DM 是一个完整的脚本部署引擎,但实际上感觉不像 cloudformation 那样可配置(它允许您使用命令行参数替换几乎任何模板值)
    • 请查看此Setting values for template properties on the command-line documentation,如果它对您有帮助,请告诉我。如果您在文档中找不到好的解决方案,那么您可能不得不采用使用模板的解决方法。
    猜你喜欢
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多