ansible-ghetto-json icon indicating copy to clipboard operation
ansible-ghetto-json copied to clipboard

Is this module supported array?

Open rangsan opened this issue 8 years ago • 4 comments

This module is very useful for me but I have the case to edit array object. Is this support ?

rangsan avatar Sep 15 '17 04:09 rangsan

same problem here. Sounds like it does not support arrays unfortunately. :(

hanynowsky avatar Oct 09 '17 17:10 hanynowsky

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.

bryanlarsen avatar Nov 01 '17 14:11 bryanlarsen

I have updated it to support array of jsons, will send a PR shortly.

mdnk avatar Nov 03 '17 22:11 mdnk

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.

dagwieers avatar Mar 04 '20 13:03 dagwieers