Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this module supported array? #6

Open
rangsan opened this issue Sep 15, 2017 · 4 comments
Open

Is this module supported array? #6

rangsan opened this issue Sep 15, 2017 · 4 comments

Comments

@rangsan
Copy link

rangsan commented Sep 15, 2017

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

@hanynowsky
Copy link

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

@bryanlarsen
Copy link
Contributor

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.

@mdnk
Copy link

mdnk commented Nov 3, 2017

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

@dagwieers
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants