From 22d657d3c7fe75326495d1730c6203b5f61f478b Mon Sep 17 00:00:00 2001 From: Benjamin Jolivot Date: Wed, 1 Mar 2017 17:20:51 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20#22130=20(ini=5Ffile=20crash=20when=20des?= =?UTF-8?q?tination=20file=20don't=20exists=20or=20is=20e=E2=80=A6=20(#221?= =?UTF-8?q?32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #22130 (ini_file crash when destination file don't exists or is empty) --- lib/ansible/modules/files/ini_file.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ansible/modules/files/ini_file.py b/lib/ansible/modules/files/ini_file.py index 7ccad907369..edddcc46bab 100644 --- a/lib/ansible/modules/files/ini_file.py +++ b/lib/ansible/modules/files/ini_file.py @@ -176,6 +176,10 @@ def do_ini(module, filename, section=None, option=None, value=None, changed = False + # ini file could be empty + if not ini_lines: + ini_lines.append('\n') + # last line of file may not contain a trailing newline if ini_lines[-1] == "" or ini_lines[-1][-1] != '\n': ini_lines[-1] += '\n'