pamd - fixed single line issue (#2989) (#3012)

* fixed pamd single line issue

* added changelog fragment

* supported case for 0 lines, improved test

(cherry picked from commit a3a40f6de3)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-07-14 13:22:01 +02:00 committed by GitHub
parent 34f963e2f4
commit acc77182bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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'