From 4e787f17cf0893965c2e95bb2188a39bb8b063ea Mon Sep 17 00:00:00 2001 From: Ales Nosek Date: Fri, 30 Oct 2015 21:57:25 -0700 Subject: [PATCH] Make the syntax work with Python 2.4 --- lib/ansible/modules/files/ini_file.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/files/ini_file.py b/lib/ansible/modules/files/ini_file.py index 5d6df779cf0..d837c329d4b 100644 --- a/lib/ansible/modules/files/ini_file.py +++ b/lib/ansible/modules/files/ini_file.py @@ -103,10 +103,13 @@ import sys def do_ini(module, filename, section=None, option=None, value=None, state='present', backup=False): - with open(filename, 'r') as ini_file: + ini_file = open(filename, 'r') + try: ini_lines = ini_file.readlines() # append a fake section line to simplify the logic ini_lines.append('[') + finally: + ini_file.close() within_section = not section section_start = 0 @@ -168,8 +171,11 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese if changed and not module.check_mode: if backup: module.backup_local(filename) - with open(filename, 'w') as ini_file: + ini_file = open(filename, 'w') + try: ini_file.writelines(ini_lines) + finally: + ini_file.close() return changed