zuul-jobs/roles/update-json-file/README.rst
Ian Wienand 0b9fad9583 update-json-file: add role to combine values into a .json
Ansible doens't really have a great built-in way to modify a json file
(unlike ini files).  The extant docker role does what seems to be the
usual standard, which is slurp in the file, parse it and then write it
back out.

In a follow-on change (I338616c41a65b007d56648fdab6da2a6a6b909f4) we
need to set some more values in the docker configuration .json file,
which made me think it's generic enough that we can have a role to
basically run read the file, |combine and write it back out.

This adds such a role with various options, and converts the existing
json configuration update in ensure-docker to use it.

Change-Id: I155a409945e0175249cf2dc630b839c7a97fb452
2020-10-05 15:18:58 +11:00

49 lines
1.1 KiB
ReStructuredText

Update JSON file
This role reads a JSON file, merges it with supplied values using
Ansible's ``combine`` filter and writes it back out. It is useful for
updating configuration files. Note this role is not currently
idempotent and will write the file each time.
**Role Variables**
.. zuul:rolevar:: update_json_file_name
:type: path
The path to the file to edit.
.. zuul:rolevar:: update_json_file_combine
:type: object
The data to be combined with the existing file data. This uses the
Jinja ``combine`` filter.
.. zuul:rolevar:: update_json_file_debug
:default: false
:type: bool
If enabled, output the combined result in a debug task.
.. zuul:rolevar:: update_json_file_default
:default: {}
The default value if the given file does not exist.
.. zuul:rolevar:: update_json_file_become
:type: bool
:default: false
The ``become:`` status when writing out the new file.
.. zuul:rolevar:: update_json_file_mode
The mode for the combined file.
.. zuul:rolevar:: update_json_file_user
The user for the combined file.
.. zuul:rolevar:: update_json_file_group
The group for the combined file.