ansible-jsonpatch icon indicating copy to clipboard operation
ansible-jsonpatch copied to clipboard

The add operator is now capable of creating the path if parents are missing

Open Chilinot opened this issue 2 years ago • 2 comments

This PR also:

  • Updates the patch() function to default to modified = false for better readability.
  • Updates the testsuite to test the local python file instead of the globally installed json_patch module.

Chilinot avatar Aug 10 '22 10:08 Chilinot

I'm a little torn on this, as RFC 6901 actually defines a nonexistent path as an error condition. That was the general thinking while I was building this out.

However, I also recognize that even by the language of the RFC, handling of the condition is up to the application. This does seem like a useful feature, but it's worth noting that it may break existing implementations out there using this module.

So as to not break the existing implementations maybe we can add another parameter like say "force" and get the user to set it to 'true' or 'false' depending on whether the user intends to add a non-existing value or patch an existing one. If default is set to 'false' then throws an error upon not finding the property on patch operations. That way we shift the burden on to the user to be aware of the schema.

rdxsuper avatar May 02 '23 01:05 rdxsuper

add another parameter like say "force"

I like this idea. I'd probably lean toward using create rather than force however, as I believe the former is more in line with other builtin Ansible modules' behavior (such as lineinfile).

So the behavior remains the same for existing deployments, but the addition of create: yes tells the module to create the key if it doesn't exist rather than throwing an exception. I'm good with it.

@Chilinot?

particledecay avatar May 02 '23 02:05 particledecay