yq
yq copied to clipboard
Multiply (merge) support appending arrays without creating duplicates
Request When merging yaml files containing arrays using the "+" flag, it will create duplicates if some of the arrays are equal in the two documents. I would like an additional flag("a" in the example) which appends lists without creating duplicates.
Example If we have data1.yml like:
equalList:
- a
- b
changedList:
- a
- b
And data2.yml like:
equalList:
- a
- b
changedList:
- c
And we run a command:
yq eval-all '. as $item ireduce ({}; . *+ $item)' data1.yml data2.yml
the current output is:
equalList:
- a
- b
- a
- b
changedList:
- a
- b
- c
With a new flag ("a" in this example) the output should be:
yq eval-all '. as $item ireduce ({}; . *a $item)' data1.yml data2.yml
equalList:
- a
- b
changedList:
- a
- b
- c
we do this here: https://github.com/openstack/kolla-ansible/tree/stable/yoga/ansible/action_plugins
is this of any use?