summaryrefslogtreecommitdiffstats
path: root/ansible/library/json_add.py
diff options
context:
space:
mode:
authorPetr Ospalý <p.ospaly@partner.samsung.com>2019-03-04 06:56:33 +0100
committerPetr Ospalý <p.ospaly@partner.samsung.com>2019-03-18 18:38:29 +0100
commitf604d490d97e3b580029bd4cfade324174555dc2 (patch)
tree6d76ae8eebfb0242c41b8d5b576c796713a83435 /ansible/library/json_add.py
parentc3bdc3210bbaf715805059bfef9b182051b3aa0c (diff)
Add default logging settings for docker
- Default configuration of logging for docker daemon. - New ansible module for generic handling of JSON files. - New setting in ansible.cfg: jinja2_native = True To preserve double-quotes in json values (OOM-1698). Issue-ID: OOM-1681 Change-Id: I8f8e19ebc290fd48a63146e96f418b98344e4433 Signed-off-by: Petr Ospalý <p.ospaly@partner.samsung.com>
Diffstat (limited to 'ansible/library/json_add.py')
-rw-r--r--ansible/library/json_add.py90
1 files changed, 0 insertions, 90 deletions
diff --git a/ansible/library/json_add.py b/ansible/library/json_add.py
deleted file mode 100644
index 6aad2d7c..00000000
--- a/ansible/library/json_add.py
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/python
-
-from ansible.module_utils.basic import AnsibleModule
-import json
-import os
-
-DOCUMENTATION="""
----
-module: json_add
-descritption:
- - This module will search top level objects in json and adds specified
- value into list for specified key.
- - If file does not exists module will create it automatically.
-
-options:
- path:
- required: true
- aliases=[name, destfile, dest]
- description:
- - The json file to modify.
- key:
- required: true
- description:
- - Top level object.
- value:
- required: true
- description:
- - Value to add to specified key.
-"""
-
-def load_json(path):
- if os.path.exists(path):
- with open(path, 'r') as f:
- return json.load(f)
- else:
- return {}
-
-def value_is_set(path, key, value, json_obj):
- return value in json_obj.get(key, [])
-
-def insert_to_json(path, key, value, check_mode=False):
- json_obj = load_json(path)
- if not value_is_set(path, key, value, json_obj):
- if not check_mode:
- json_obj.setdefault(key, []).append(value)
- store_json(path, json_obj)
- return True, 'Value %s added to %s.' % (value, key)
- else:
- return False, ''
-
-def store_json(path, json_obj):
- with open(path, 'w') as f:
- json.dump(json_obj, f, indent=4)
-
-def check_file_attrs(module, changed, message, diff):
- file_args = module.load_file_common_arguments(module.params)
- if module.set_fs_attributes_if_different(file_args, False, diff=diff):
-
- if changed:
- message += ' '
- changed = True
- message += 'File attributes changed.'
-
- return changed, message
-
-def run_module():
- module = AnsibleModule(
- argument_spec=dict(
- path=dict(type='path', required=True, aliases=['name', 'destfile', 'dest']),
- key=dict(type='str', required=True),
- value=dict(type='str', required=True),
- ),
- add_file_common_args=True,
- supports_check_mode=True
- )
- params = module.params
- path = params['path']
- key = params['key']
- value = params['value']
- try:
- changed, msg = insert_to_json(path, key, value, module.check_mode)
- fs_diff = {}
- changed, msg = check_file_attrs(module, changed, msg, fs_diff)
- module.exit_json(changed=changed, msg=msg, file_attr_diff=fs_diff)
- except IOError as e:
- module.fail_json(msg=e.msg)
-
-if __name__ == '__main__':
- run_module()
-