Skip to content

Merge two files with anchors and getting reference errors #1694

Open
@fabioluciano

Description

@fabioluciano

Describe the bug

I`m trying to merge two documents and i got a error in reference anchors

Version of yq: v4.34.1
Operating system: mac
Installed via: homebrew

Input Yaml
default.yml

services:
  kafka:
    username: &kafka_username username
    password: &kafka_password password
    servers: &kafka_servers
     - server
     - server
     - server
applications:
  app01:
    version: 1.0.0
    variables:
      kafka_servers: *kafka_servers
      kafka_usernane: *kafka_username
      kafka_password: *kafka_password

other.yml

applications:
  app02:
    version: 2.0.0
  app03:
    version: 1.0.0
    variables:
      kafka_servers: *kafka_servers
      kafka_usernane: *kafka_username
      kafka_password: *kafka_password

Command

yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' defaut.yml other.yml

Actual behavior

Error: bad file 'other.yml': yaml: unknown anchor 'kafka_servers' referenced

Expected behavior

services:
  kafka:
    username: &kafka_username username
    password: &kafka_password password
    servers: &kafka_servers
      - server
      - server
      - server
applications:
  app01:
    version: 1.0.0
    variables:
      kafka_servers: *kafka_servers
      kafka_usernane: *kafka_username
      kafka_password: *kafka_password
  app02:
    version: 2.0.0
    variables:
      kafka_servers: *kafka_servers
      kafka_usernane: *kafka_username
      kafka_password: *kafka_password
  app03:
    version: 1.0.0
    variables:
      kafka_servers: *kafka_servers
      kafka_usernane: *kafka_username
      kafka_password: *kafka_password

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions