From 1d4c0abe2902d91b2895452feedcf72bf3dd9e20 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 7 Sep 2016 12:18:33 -0400 Subject: [PATCH] added backup_file to module returns (#4723) fixes #14502 also cleaned up some unused stuff and fixed imports --- files/ini_file.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/files/ini_file.py b/files/ini_file.py index af250f42405..3b9cceecf60 100644 --- a/files/ini_file.py +++ b/files/ini_file.py @@ -101,9 +101,8 @@ EXAMPLES = ''' backup=yes ''' -import ConfigParser -import sys import os +import re # ============================================================== # match_opt @@ -199,16 +198,17 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese changed = True + backup_file = None if changed and not module.check_mode: if backup: - module.backup_local(filename) + backup_file = module.backup_local(filename) ini_file = open(filename, 'w') try: ini_file.writelines(ini_lines) finally: ini_file.close() - return changed + return (changed, backup_file) # ============================================================== # main @@ -229,8 +229,6 @@ def main(): supports_check_mode = True ) - info = dict() - dest = os.path.expanduser(module.params['dest']) section = module.params['section'] option = module.params['option'] @@ -239,13 +237,17 @@ def main(): backup = module.params['backup'] no_extra_spaces = module.params['no_extra_spaces'] - changed = do_ini(module, dest, section, option, value, state, backup, no_extra_spaces) + (changed,backup_file) = do_ini(module, dest, section, option, value, state, backup, no_extra_spaces) file_args = module.load_file_common_arguments(module.params) changed = module.set_fs_attributes_if_different(file_args, changed) + results = { 'changed': changed, 'msg': "OK", 'dest': dest } + if backup_file is not None: + results['backup_file'] = backup_file + # Mission complete - module.exit_json(dest=dest, changed=changed, msg="OK") + module.exit_json(**results) # import module snippets from ansible.module_utils.basic import *