Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilization: Add a Playbook name to Ansible Playbooks #10712

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading