如何让yaml的不同部分引用一个全局字段?

如何让yaml的不同部分引用一个全局字段?,yaml,Yaml,1。背景: extra_environment: postgres_password: &passwd abc newnew: POSTGRES_PASSWORD: *passwd POSTGRES_CONNECT_STRING: *passwd extra_environment: postgres_password: &passwd abc newnew: POSTGRES_PASSWORD: *passwd POSTGRES_CONNECT_S

1。背景:

extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: *passwd
extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: postgres://postgres:*passwd@db:5432/postgres
---
extra_environment:
  postgres_password: abc
newnew:
  POSTGRES_CONNECT_STRING: postgres://postgres:abc@db:5432/postgres
  POSTGRES_PASSWORD: abc
我使用yaml锚点在yaml中共享全局片段,如下所示:

trial1.yaml:

extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: *passwd
extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: postgres://postgres:*passwd@db:5432/postgres
---
extra_environment:
  postgres_password: abc
newnew:
  POSTGRES_CONNECT_STRING: postgres://postgres:abc@db:5432/postgres
  POSTGRES_PASSWORD: abc
然后我将对该yaml进行脱毛,它将使该yaml成为下一个:

---
extra_environment:
  postgres_password: abc
newnew:
  POSTGRES_CONNECT_STRING: abc
  POSTGRES_PASSWORD: abc
您可以看到
*passwd
成功呈现为
abc
,完美

2。我的问题:

extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: *passwd
extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: postgres://postgres:*passwd@db:5432/postgres
---
extra_environment:
  postgres_password: abc
newnew:
  POSTGRES_CONNECT_STRING: postgres://postgres:abc@db:5432/postgres
  POSTGRES_PASSWORD: abc
然后,我这里有另一个yaml:

trial2.yaml:

extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: *passwd
extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: postgres://postgres:*passwd@db:5432/postgres
---
extra_environment:
  postgres_password: abc
newnew:
  POSTGRES_CONNECT_STRING: postgres://postgres:abc@db:5432/postgres
  POSTGRES_PASSWORD: abc
再次转到,它作为下一步呈现给我:

--- 
extra_environment: 
  postgres_password: abc
newnew: 
  POSTGRES_CONNECT_STRING: "postgres://postgres:*passwd@db:5432/postgres"
  POSTGRES_PASSWORD: abc
看起来如果在
*
之前/之后有内容,则无法渲染

我的预期输出:

extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: *passwd
extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: postgres://postgres:*passwd@db:5432/postgres
---
extra_environment:
  postgres_password: abc
newnew:
  POSTGRES_CONNECT_STRING: postgres://postgres:abc@db:5432/postgres
  POSTGRES_PASSWORD: abc
3。问题:

extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: *passwd
extra_environment:
  postgres_password: &passwd abc

newnew:
  POSTGRES_PASSWORD: *passwd
  POSTGRES_CONNECT_STRING: postgres://postgres:*passwd@db:5432/postgres
---
extra_environment:
  postgres_password: abc
newnew:
  POSTGRES_CONNECT_STRING: postgres://postgres:abc@db:5432/postgres
  POSTGRES_PASSWORD: abc
对于我的情况,如果可能的话,yaml可以有任何方法来处理这个问题吗?不仅限于yaml anchor,其他人也适合我