user3325776
user3325776

Reputation: 105

Update specific value in an array of key=value pairs in YAML

Given the following snippet from a yml file, how can I change the value of MAINTENANCE_MODE to true?

A solution using mikefarah/yq v4.18+ is preferred.

web:
  environment:
    - DEBUG=1
    - PORT=8082
    - MAINTENANCE_MODE=false
    - APP_HOME=/opt/app

Upvotes: 0

Views: 4371

Answers (1)

pmf
pmf

Reputation: 36088

If you know that it's in this position, use

yq -i '.web.environment[2] = "MAINTENANCE_MODE=true"' input.yml

If you have to look it up, use

yq -i '.web.environment[] |= sub("^(MAINTENANCE_MODE=).*$", "${1}true")' input.yml

Upvotes: 1

Related Questions