Blame SOURCES/scap-security-guide-0.1.57-ansible-playbooks-per-rule-PR_7039.patch

a8c580
commit c58a2b0af3c8094446df1850cb1c943d51b2ec5f
a8c580
Author: Gabriel Becker <ggasparb@redhat.com>
a8c580
Date:   Tue Jun 8 13:40:28 2021 +0200
a8c580
a8c580
    Add option to enable installation of individual ansible playbooks per rule.
a8c580
a8c580
diff --git a/CMakeLists.txt b/CMakeLists.txt
a8c580
index 6995944..bd317c0 100644
a8c580
--- a/CMakeLists.txt
a8c580
+++ b/CMakeLists.txt
a8c580
@@ -46,6 +46,7 @@ option(SSG_SHELLCHECK_BASH_FIXES_VALIDATION_ENABLED "If enabled, shellcheck vali
a8c580
 option(SSG_LINKCHECKER_VALIDATION_ENABLED "If enabled, linkchecker will be used to validate URLs in all the HTML guides and tables." TRUE)
a8c580
 option(SSG_SVG_IN_XCCDF_ENABLED "If enabled, the built XCCDFs will include the SVG SCAP Security Guide logo." TRUE)
a8c580
 option(SSG_SEPARATE_SCAP_FILES_ENABLED "If enabled, separate SCAP files (OVAL, XCCDF, CPE dict, ...) will be installed alongside the source data-streams" TRUE)
a8c580
+option(SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED "If enabled, Ansible Playbooks for each rule will be built and installed." FALSE)
a8c580
 option(SSG_JINJA2_CACHE_ENABLED "If enabled, the jinja2 templating files will be cached into bytecode. Also see SSG_JINJA2_CACHE_DIR." TRUE)
a8c580
 option(SSG_BATS_TESTS_ENABLED "If enabled, bats will be used to run unit-tests of bash remediations." TRUE)
a8c580
 set(SSG_JINJA2_CACHE_DIR "${CMAKE_BINARY_DIR}/jinja2_cache" CACHE PATH "Where the jinja2 cached bytecode should be stored. This speeds up builds at the expense of disk space. You can use one location for multiple SSG builds for performance improvements.")
a8c580
@@ -231,6 +232,7 @@ message(STATUS "OVAL schematron validation: ${SSG_OVAL_SCHEMATRON_VALIDATION_ENA
a8c580
 message(STATUS "shellcheck bash fixes validation: ${SSG_SHELLCHECK_BASH_FIXES_VALIDATION_ENABLED}")
a8c580
 message(STATUS "SVG logo in XCCDFs: ${SSG_SVG_IN_XCCDF_ENABLED}")
a8c580
 message(STATUS "Separate SCAP files: ${SSG_SEPARATE_SCAP_FILES_ENABLED}")
a8c580
+message(STATUS "Ansible Playbooks Per Rule: ${SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED}")
a8c580
 if (SSG_JINJA2_CACHE_ENABLED)
a8c580
     message(STATUS "jinja2 cache: enabled")
a8c580
     message(STATUS "jinja2 cache dir: ${SSG_JINJA2_CACHE_DIR}")
a8c580
diff --git a/cmake/SSGCommon.cmake b/cmake/SSGCommon.cmake
a8c580
index b487a0b..b7db7fd 100644
a8c580
--- a/cmake/SSGCommon.cmake
a8c580
+++ b/cmake/SSGCommon.cmake
a8c580
@@ -746,8 +746,12 @@ macro(ssg_build_product PRODUCT)
a8c580
     ssg_build_xccdf_unlinked(${PRODUCT})
a8c580
     ssg_build_ocil_unlinked(${PRODUCT})
a8c580
     ssg_build_remediations(${PRODUCT})
a8c580
-    if ("${PRODUCT_ANSIBLE_REMEDIATION_ENABLED}")
a8c580
+    if ("${PRODUCT_ANSIBLE_REMEDIATION_ENABLED}" AND SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED)
a8c580
         ssg_build_ansible_playbooks(${PRODUCT})
a8c580
+        add_dependencies(
a8c580
+            ${PRODUCT}-content
a8c580
+            generate-${PRODUCT}-ansible-playbooks
a8c580
+        )
a8c580
     endif()
a8c580
     ssg_build_xccdf_with_remediations(${PRODUCT})
a8c580
     ssg_build_oval_unlinked(${PRODUCT})
a8c580
@@ -778,10 +782,6 @@ macro(ssg_build_product PRODUCT)
a8c580
     add_dependencies(zipfile "generate-ssg-${PRODUCT}-ds.xml")
a8c580
 
a8c580
     if ("${PRODUCT_ANSIBLE_REMEDIATION_ENABLED}")
a8c580
-        add_dependencies(
a8c580
-            ${PRODUCT}-content
a8c580
-            generate-${PRODUCT}-ansible-playbooks
a8c580
-        )
a8c580
         ssg_build_profile_playbooks(${PRODUCT})
a8c580
         add_custom_target(
a8c580
             ${PRODUCT}-profile-playbooks
a8c580
@@ -885,6 +885,20 @@ macro(ssg_build_product PRODUCT)
a8c580
         endif()
a8c580
         "
a8c580
     )
a8c580
+    if(SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED)
a8c580
+        install(
a8c580
+            CODE "
a8c580
+            file(GLOB PLAYBOOK_PER_RULE_FILES \"${CMAKE_BINARY_DIR}/${PRODUCT}/playbooks/*\") \n
a8c580
+            if(NOT IS_ABSOLUTE ${SSG_ANSIBLE_ROLE_INSTALL_DIR}/rule_playbooks)
a8c580
+                file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${SSG_ANSIBLE_ROLE_INSTALL_DIR}/rule_playbooks/${PRODUCT}\"
a8c580
+                    TYPE FILE FILES \${PLAYBOOK_PER_RULE_FILES})
a8c580
+            else()
a8c580
+                file(INSTALL DESTINATION \"${SSG_ANSIBLE_ROLE_INSTALL_DIR}/rule_playbooks/${PRODUCT}\"
a8c580
+                    TYPE FILE FILES \${PLAYBOOK_PER_RULE_FILES})
a8c580
+            endif()
a8c580
+            "
a8c580
+        )
a8c580
+    endif()
a8c580
 
a8c580
     # grab all the kickstarts (if any) and install them
a8c580
     file(GLOB KICKSTART_FILES "${CMAKE_CURRENT_SOURCE_DIR}/kickstart/ssg-${PRODUCT}-*-ks.cfg")