ansible-ghetto-json
ansible-ghetto-json copied to clipboard
Is this module supported array?
This module is very useful for me but I have the case to edit array object. Is this support ?
same problem here. Sounds like it does not support arrays unfortunately. :(
There are now two separate PR's to support lists. @hanynowsky's #7 lets you set a json array to have the value of an ansible array, and @moises-silva's #2 lets you treat a json array as a set and add values to it.
Neither PR will meet everybody's needs, but one of them might work for anybody who stumbles across this.
I have updated it to support array of jsons, will send a PR shortly.
One solution could be to use yaml tags to indicate the required transformation.
So
# Consider a_list a set to merge with
a_list: !!set [ foo, bar ]
would add list items to an existing list without adding duplicates (and order is not important).
There are a few options when modifying lists:
- Should the list be appended or prepended to the existing list (ordered lists) ?
- Should values be unique inside the list ?
Custom tags could be used for similar purposes:
# Consider b_list to replace the original
b_list: !replace [ foo, bar ]
# Consider c_list to be appended to the original
c_list: !append [ foo, bar ]
# Consider d_list to be prepended to the original
d_list: !prepend [ foo, bar ]
But if you want to indicate e.g. prepend and unique we need to have combination tags like:
- replace
- prepend
- prepend_unique
- append
- append_unique
And tags would be equally useful for dictionaries where you may want to replace a dictionary rather than merge it.