Skip to content

Commit

Permalink
Add a Playbook name to Ansible Playbooks
Browse files Browse the repository at this point in the history
In the stabilization GitHub Action CI runs all the tests
ansible-playbook-per-profile-ansible-lint-check-.*
fail due to a missing name. This can be easily fixed by
assigning a name to all the playbooks.

Addressing:
name[play]: All plays should be named.
  • Loading branch information
jan-cerny committed Jun 14, 2023
1 parent 5d417c3 commit f4ff0c0
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 f4ff0c0

Please sign in to comment.