0b9fad9583
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
41 lines
942 B
YAML
41 lines
942 B
YAML
- hosts: all
|
|
tasks:
|
|
|
|
- include_role:
|
|
name: update-json-file
|
|
vars:
|
|
update_json_file_name: test.json
|
|
update_json_file_default:
|
|
foo: bar
|
|
update_json_file_combine:
|
|
moo: boo
|
|
update_json_file_debug: true
|
|
|
|
- include_role:
|
|
name: update-json-file
|
|
vars:
|
|
update_json_file_name: test.json
|
|
update_json_file_combine:
|
|
new: content
|
|
a:
|
|
- list
|
|
- of
|
|
- items
|
|
update_json_file_debug: true
|
|
|
|
- name: Load resulting merged file
|
|
slurp:
|
|
path: 'test.json'
|
|
register: _file
|
|
|
|
- name: Parse merged file
|
|
set_fact:
|
|
_config: "{{ _file.content | b64decode | from_json }}"
|
|
|
|
- assert:
|
|
that:
|
|
- _config['foo'] == 'bar'
|
|
- _config['moo'] == 'boo'
|
|
- _config['new'] == 'content'
|
|
- _config['a'] == ['list', 'of', 'items']
|