yaml - 在 YAML 文件中插入变量/常量

标签 yaml

假设我想避免在 YAML 文件中多次插入相同的值:

- name: region_1
  inputs:
    tag_name: constant_tag_name
    aws_region: us-east-1

- name: region_2
  inputs:
    tag_name: constant_tag_name
    aws_region: us-west-2
...

所以在上面的示例中,我想在所有部分上方的某处定义一个变量,其值为 constant_tag_name 并在所有值相同的地方提及该变量。如果要更改名称,我想在顶部更改它并让它在所有地方都得到反射(reflect)。我查看了 YAML 别名,但它们似乎用于代码部分,而这里我只有一个变量。你能指导我吗?

最佳答案

你应该使用一个别名,像这样:

- const_tag: &CT "constant_tag_name"
- name: region_1
  inputs:
    tag_name: *CT
    aws_region: us-east-1
- name: region_2
  inputs:
    tag_name: *CT
    aws_region: us-west-2

在这里试试:yaml-online-parser.appspot.com

关于yaml - 在 YAML 文件中插入变量/常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66684747/

相关文章:

用于 YAML 到 JAXB 映射的 Java 库

javascript - 如何在 JS 文件中使用 Github secret

amazon-web-services - AWS 云形成 : The security group 'sg-' does not exist in default VPC 'vpc'

symfony2 : how to include line breaks/newlines in translations?

python - PyYAML 错误 : "yaml.scanner.ScannerError: mapping values are not allowed here"

ruby-on-rails - 您对众包翻译管理系统有何建议?

database - Liquibase:columnName 是必需的

amazon-web-services - AWS Cloudformation IoTAnalytics ServiceManagedS3 YAML

windows - Windows 中 Kubernetes .yaml 中 PersistentVolume 的路径

Symfony 2 onDelete setNull