Skip to content

Commit

Permalink
Merge pull request #10712 from jan-cerny/ansible_name_stabilization
Browse files Browse the repository at this point in the history
Stabilization: Add a Playbook name to Ansible Playbooks
  • Loading branch information
Mab879 committed Jun 14, 2023
2 parents 5d417c3 + f4ff0c0 commit 513280d
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 add_play_name(ansible_src, profile):
old_play_start = r"^( *)- hosts: all"
new_play_start = (
r"\1- name: Ansible Playbook for %s\n\1 hosts: all" % (profile))
return re.sub(old_play_start, new_play_start, ansible_src, flags=re.M)


def remove_too_many_blank_lines(ansible_src):
"""
Condenses three or more empty lines as two.
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,
add_play_name,
remove_too_many_blank_lines,
remove_trailing_whitespace,
strip_eof,
Expand Down Expand Up @@ -138,6 +139,7 @@ def builder(queue):
if extension == "yml" and \
template == "urn:xccdf:fix:script:ansible":
src = add_minimum_version(src)
src = add_play_name(src, profile_id)
src = remove_too_many_blank_lines(src)
src = remove_trailing_whitespace(src)
src = strip_eof(src)
Expand Down

0 comments on commit 513280d

Please sign in to comment.