如何在已解包的锚下重用锚定条目? [英] How to reuse anchored entry under already unwrapped anchor?

查看:70
本文介绍了如何在已解包的锚下重用锚定条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个CircleCI配置,该配置将允许我重用整个列表/映射(?)条目及其属性。

I am trying to write a CircleCI config that will allow me to reuse both whole list/mapping(?) entries and its properties.

具有以下内容:

image_definitions:
  docker:
    - &default_localstack_image
      image: localstack/localstack:0.10.3
      environment:
        KINESIS_LATENCY: 0
defaults_env: &defaults_env
  environment:
    PG_PORT: 5432
    PG_USER: root

我希望能够替换:

test: &test
  docker:
    - image: localstack/localstack:0.10.3
      <<: *defaults_env

,例如:

test: &test
  docker:
    - *default_localstack_image
      <<: *defaults_env

,但这种方式不起作用。

but it doesn't work this way.

我也尝试过:

test: &test
  docker:
    - *default_localstack_image
      *defaults_env

但是那也没有用。

我该怎么做?

推荐答案

根据文档

test: &test
  docker:
    - <<: [*default_localstack_image, *defaults_env]

但是,请注意,合并功能不是YAML规范的一部分,仅针对过时的YAML 1.1进行了定义。我不知道这是否真正实施。即使是这种情况,也请注意,此合并键是一个奇怪的问题–违反了说明每个标签都将映射到一个类型的规范,即使该规范定义的加载过程已将其解释为转换指令没有执行转换步骤的地方。

However, be aware that the merge feature is not part of the YAML spec and has only been defined for outdated YAML 1.1. I don't know if this is actually implemented. Even if it is, be aware that this merge key is the odd man out – violating the spec that says every tag is to be mapped to a type, it is instead interpreted as transformation instruction even though the loading process as defined by the spec has no place for executing transformation steps.

类似的功能(例如,用于连接标量)在SO上或多或少地被请求,但是不可用(可能永远不会)如果您需要做这样的事情,我的建议是做例如Ansible和SaltStack做并使用模板引擎作为YAML文件的预处理器。

Similar functionality (for example for concatenating scalars) is more or less frequently requested on SO but is not available (and will probably never be) and if you need to do something like this, my advice is to do what e.g. Ansible and SaltStack do and use a templating engine as preprocessor for your YAML file.

这篇关于如何在已解包的锚下重用锚定条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆