pamd - fixed single line issue (#2989)

* fixed pamd single line issue

* added changelog fragment

* supported case for 0 lines, improved test
This commit is contained in:
Alexei Znamensky
2021-07-14 23:04:35 +12:00
committed by GitHub
parent 28193b699b
commit a3a40f6de3
4 changed files with 72 additions and 4 deletions

View File

@@ -733,14 +733,19 @@ class PamdService(object):
lines = []
current_line = self._head
mark = "# Updated by Ansible - %s" % datetime.now().isoformat()
while current_line is not None:
lines.append(str(current_line))
current_line = current_line.next
if lines[1].startswith("# Updated by Ansible"):
lines.pop(1)
lines.insert(1, "# Updated by Ansible - " + datetime.now().isoformat())
if len(lines) <= 1:
lines.insert(0, "")
lines.insert(1, mark)
else:
if lines[1].startswith("# Updated by Ansible"):
lines[1] = mark
else:
lines.insert(1, mark)
return '\n'.join(lines) + '\n'