Skip to content

Commit

Permalink
fix: ansible build_profile_remediations: add and use remove_too_many_…
Browse files Browse the repository at this point in the history
…blank_lines

Without this ansible-playbook-per-profile-yamllint-check tests fail as
between rule segments there can be extra lines because of some reason.

Like:
./fedora-playbook-standard.yml
  342:1     warning  too many blank lines (5 > 2)  (empty-lines)
  1124:1    warning  too many blank lines (3 > 2)  (empty-lines)
...
  • Loading branch information
maage committed Mar 26, 2023
1 parent 3460217 commit 89dd0c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ssg/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def add_minimum_version(ansible_src):
return ansible_src.replace(" - hosts: all", pre_task, 1)


def remove_too_many_blank_lines(ansible_src):
"""
Condenses three or more empty lines as two.
"""
return re.sub(r'\n{4,}', '\n\n\n', ansible_src, 0, flags=re.M)


def remove_trailing_whitespace(ansible_src):
"""
Removes trailing whitespace in an Ansible script
Expand Down
2 changes: 2 additions & 0 deletions ssg/build_profile_remediations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .ansible import (
add_minimum_version,
remove_too_many_blank_lines,
remove_trailing_whitespace,
strip_eof,
)
Expand Down Expand Up @@ -137,6 +138,7 @@ def builder(queue):
if extension == "yml" and \
template == "urn:xccdf:fix:script:ansible":
src = add_minimum_version(src)
src = remove_too_many_blank_lines(src)
src = remove_trailing_whitespace(src)
src = strip_eof(src)
with open(path, "wb") as _file:
Expand Down

0 comments on commit 89dd0c0

Please sign in to comment.