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'