How to reuse anchored entry under already unwrapped anchor?

血红的双手。 提交于 2019-12-11 06:17:09

问题


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

Having the following:

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

I would like to be able to replace:

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

with something like:

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

but it doesn't work this way.

I've also tried:

test: &test
  docker:
    - *default_localstack_image
      *defaults_env

but that also didn't work.

How can I do that?


回答1:


According to the documentation:

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

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.

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.



来源:https://stackoverflow.com/questions/58095057/how-to-reuse-anchored-entry-under-already-unwrapped-anchor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!