Blame SOURCES/scap-security-guide-0.1.58-tests_for_playbooks_that_change_banners-PR_7376.patch

889f2b
From bf018e9f8327b231b967db8ec74fabf01802b6a8 Mon Sep 17 00:00:00 2001
889f2b
From: Watson Sato <wsato@redhat.com>
889f2b
Date: Wed, 11 Aug 2021 09:45:04 +0200
889f2b
Subject: [PATCH 1/3] Add test for ansible files removed and readded
889f2b
889f2b
Check if any playbook removes a file and then add it back again.
889f2b
The file removal is based on the 'file' module with 'state: absent', and
889f2b
the reintroduction of the file is based on 'lineinfile', 'blockinfile'
889f2b
and 'copy' modules.
889f2b
---
889f2b
 CMakeLists.txt                               |  2 +
889f2b
 tests/CMakeLists.txt                         |  8 ++
889f2b
 tests/test_ansible_file_removed_and_added.py | 97 ++++++++++++++++++++
889f2b
 3 files changed, 107 insertions(+)
889f2b
 create mode 100644 tests/test_ansible_file_removed_and_added.py
889f2b
889f2b
diff --git a/CMakeLists.txt b/CMakeLists.txt
889f2b
index 330b869d0f9..e41f2caa630 100644
889f2b
--- a/CMakeLists.txt
889f2b
+++ b/CMakeLists.txt
889f2b
@@ -129,6 +129,7 @@ find_python_module(jinja2 REQUIRED)
889f2b
 find_python_module(pytest)
889f2b
 find_python_module(pytest_cov)
889f2b
 find_python_module(json2html)
889f2b
+find_python_module(yamlpath)
889f2b
 
889f2b
 # sphinx documentation requirements
889f2b
 find_python_module(sphinx)
889f2b
@@ -231,6 +232,7 @@ message(STATUS "python pytest module (optional): ${PY_PYTEST}")
889f2b
 message(STATUS "ansible-playbook module (optional): ${ANSIBLE_PLAYBOOK_EXECUTABLE}")
889f2b
 message(STATUS "ansible-lint module (optional): ${ANSIBLE_LINT_EXECUTABLE}")
889f2b
 message(STATUS "yamllint module (optional): ${YAMLLINT_EXECUTABLE}")
889f2b
+message(STATUS "yamlpath module (optional): ${PY_YAMLPATH}")
889f2b
 message(STATUS "BATS framework (optional): ${BATS_EXECUTABLE}")
889f2b
 message(STATUS "python sphinx module (optional): ${PY_SPHINX}")
889f2b
 message(STATUS "python sphinxcontrib.autojinja module (optional): ${PY_SPHINXCONTRIB.AUTOJINJA}")
889f2b
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
889f2b
index 3e2d8a4ec31..739cc124035 100644
889f2b
--- a/tests/CMakeLists.txt
889f2b
+++ b/tests/CMakeLists.txt
889f2b
@@ -121,3 +121,11 @@ add_test(
889f2b
 )
889f2b
 set_tests_properties("fix_rules-sort_subkeys" PROPERTIES LABELS quick)
889f2b
 set_tests_properties("fix_rules-sort_subkeys" PROPERTIES DEPENDS "test-rule-dir-json")
889f2b
+
889f2b
+if (PY_YAMLPATH)
889f2b
+    add_test(
889f2b
+        NAME "ansible-file-removed-and-added"
889f2b
+        COMMAND env "PYTHONPATH=$ENV{PYTHONPATH}" "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test_ansible_file_removed_and_added.py" --ansible_dir "${CMAKE_BINARY_DIR}/ansible"
889f2b
+    )
889f2b
+    set_tests_properties("fix_rules-sort_subkeys" PROPERTIES LABELS quick)
889f2b
+endif()
889f2b
diff --git a/tests/test_ansible_file_removed_and_added.py b/tests/test_ansible_file_removed_and_added.py
889f2b
new file mode 100644
889f2b
index 00000000000..23f6f888bda
889f2b
--- /dev/null
889f2b
+++ b/tests/test_ansible_file_removed_and_added.py
889f2b
@@ -0,0 +1,97 @@
889f2b
+#!/usr/bin/python3
889f2b
+
889f2b
+import argparse
889f2b
+import os
889f2b
+import sys
889f2b
+from types import SimpleNamespace
889f2b
+from yamlpath import Processor
889f2b
+from yamlpath import YAMLPath
889f2b
+from yamlpath.common import Parsers
889f2b
+from yamlpath.exceptions import YAMLPathException
889f2b
+from yamlpath.wrappers import ConsolePrinter
889f2b
+
889f2b
+
889f2b
+def parse_command_line_args():
889f2b
+    parser = argparse.ArgumentParser(
889f2b
+        description="Checks if an Ansible Playbook removes a file and then adds it again.")
889f2b
+    parser.add_argument("--ansible_dir", required=True,
889f2b
+                        help="Directory containing Ansible Playbooks")
889f2b
+    args = parser.parse_args()
889f2b
+    return args
889f2b
+
889f2b
+
889f2b
+def check_playbook_file_removed_and_added(playbook_path):
889f2b
+    playbook_ok = True
889f2b
+
889f2b
+    yaml_parser = Parsers.get_yaml_editor()
889f2b
+
889f2b
+    logging_args = SimpleNamespace(quiet=False, verbose=False, debug=False)
889f2b
+    log = ConsolePrinter(logging_args)
889f2b
+
889f2b
+    # Find every path removed by a file Task (also matches tasks within blocks)
889f2b
+    files_absent_string = "tasks.**.file[state=absent][parent()].path"
889f2b
+    files_absent_yamlpath = YAMLPath(files_absent_string)
889f2b
+    path_editing_tasks_yamlpath = ""
889f2b
+
889f2b
+    log.info("Info: Evaluating playbook '{}'".format(playbook_path))
889f2b
+    (yaml_data, doc_loaded) = Parsers.get_yaml_data(yaml_parser, log, playbook_path)
889f2b
+    if not doc_loaded:
889f2b
+        # There was an issue loading the file; an error message has already been
889f2b
+        # printed via ConsolePrinter.
889f2b
+        return False
889f2b
+
889f2b
+    processor = Processor(log, yaml_data)
889f2b
+    try:
889f2b
+        for node in processor.get_nodes(files_absent_yamlpath, mustexist=False):
889f2b
+            path = str(node)
889f2b
+            # 'node' is a NodeCoords.
889f2b
+            if path == 'None':
889f2b
+                continue
889f2b
+            elif "{{" in path:
889f2b
+                # Identified path is a Jinja expression, unfortunately there is no easy way to get
889f2b
+                # the actual path without making this test very complicated
889f2b
+                continue
889f2b
+
889f2b
+            # Check if this paths is used in any of the following ansible modules
889f2b
+            ansible_modules = ["lineinfile", "blockinfile", "copy"]
889f2b
+            path_editing_tasks_string = "tasks.**.[.=~/{modules}/][*='{path}'][parent()].name"
889f2b
+            path_editing_tasks_yamlpath = YAMLPath(path_editing_tasks_string.format(
889f2b
+                modules="|".join(ansible_modules),
889f2b
+                path=node)
889f2b
+                )
889f2b
+            for task in processor.get_nodes(path_editing_tasks_yamlpath, mustexist=False):
889f2b
+                log.info("Error: Task '{}' manipulates a file that is removed by another task"
889f2b
+                         .format(task))
889f2b
+                playbook_ok = False
889f2b
+    except YAMLPathException as ex:
889f2b
+        no_file_msg = ("Cannot add PathSegmentTypes.TRAVERSE subreference to lists at 'None' "
889f2b
+                       "in '{}'.")
889f2b
+        if str(ex) == no_file_msg.format(files_absent_string):
889f2b
+            log.info("Info: Playbook {} has no 'file' tasks.".format(playbook_path))
889f2b
+        elif path_editing_tasks_yamlpath and str(ex) == no_file_msg.format(
889f2b
+                path_editing_tasks_yamlpath):
889f2b
+            log.info("Info: Playbook {} has no '{}' tasks.".format(
889f2b
+                playbook_path, " ".join(ansible_modules)))
889f2b
+        else:
889f2b
+            log.info("Error: {}.".format(ex))
889f2b
+
889f2b
+    return playbook_ok
889f2b
+
889f2b
+
889f2b
+def main():
889f2b
+    args = parse_command_line_args()
889f2b
+
889f2b
+    all_playbooks_ok = True
889f2b
+    for dir_item in os.listdir(args.ansible_dir):
889f2b
+        if dir_item.endswith(".yml"):
889f2b
+            playbook_path = os.path.join(args.ansible_dir, dir_item)
889f2b
+
889f2b
+            if not check_playbook_file_removed_and_added(playbook_path):
889f2b
+                all_playbooks_ok = False
889f2b
+
889f2b
+    if not all_playbooks_ok:
889f2b
+        sys.exit(1)
889f2b
+
889f2b
+
889f2b
+if __name__ == "__main__":
889f2b
+    main()
889f2b
889f2b
From e6d727762ba446cad94f1e002fa7a7fef0f1a4cb Mon Sep 17 00:00:00 2001
889f2b
From: Watson Sato <wsato@redhat.com>
889f2b
Date: Wed, 11 Aug 2021 09:48:14 +0200
889f2b
Subject: [PATCH 2/3] Unit tests the function for file removed and added
889f2b
889f2b
Add a unit test for the core function that checks if any playbook
889f2b
removes a file and then reintroduces it back.
889f2b
---
889f2b
 tests/CMakeLists.txt                          |  6 ++
889f2b
 .../file_block_removed_and_added.yml          | 69 +++++++++++++++++++
889f2b
 .../file_not_removed_and_added.yml            | 49 +++++++++++++
889f2b
 .../file_removed_and_added.yml                | 62 +++++++++++++++++
889f2b
 .../file_removed_and_not_added.yml            | 46 +++++++++++++
889f2b
 ...t_check_playbook_file_removed_and_added.py | 39 +++++++++++
889f2b
 6 files changed, 271 insertions(+)
889f2b
 create mode 100644 tests/ansible_file_removed_and_added/file_block_removed_and_added.yml
889f2b
 create mode 100644 tests/ansible_file_removed_and_added/file_not_removed_and_added.yml
889f2b
 create mode 100644 tests/ansible_file_removed_and_added/file_removed_and_added.yml
889f2b
 create mode 100644 tests/ansible_file_removed_and_added/file_removed_and_not_added.yml
889f2b
 create mode 100644 tests/test_check_playbook_file_removed_and_added.py
889f2b
889f2b
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
889f2b
index 739cc124035..000a1b1385d 100644
889f2b
--- a/tests/CMakeLists.txt
889f2b
+++ b/tests/CMakeLists.txt
889f2b
@@ -123,6 +123,12 @@ set_tests_properties("fix_rules-sort_subkeys" PROPERTIES LABELS quick)
889f2b
 set_tests_properties("fix_rules-sort_subkeys" PROPERTIES DEPENDS "test-rule-dir-json")
889f2b
 
889f2b
 if (PY_YAMLPATH)
889f2b
+    if (PY_PYTEST)
889f2b
+        add_test(
889f2b
+            NAME "test-function-check_playbook_file_removed_and_added"
889f2b
+            COMMAND "${PYTHON_EXECUTABLE}" -m pytest ${PYTEST_COVERAGE_OPTIONS} "${CMAKE_CURRENT_SOURCE_DIR}/test_check_playbook_file_removed_and_added.py"
889f2b
+        )
889f2b
+    endif()
889f2b
     add_test(
889f2b
         NAME "ansible-file-removed-and-added"
889f2b
         COMMAND env "PYTHONPATH=$ENV{PYTHONPATH}" "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test_ansible_file_removed_and_added.py" --ansible_dir "${CMAKE_BINARY_DIR}/ansible"
889f2b
diff --git a/tests/ansible_file_removed_and_added/file_block_removed_and_added.yml b/tests/ansible_file_removed_and_added/file_block_removed_and_added.yml
889f2b
new file mode 100644
889f2b
index 00000000000..8863b333129
889f2b
--- /dev/null
889f2b
+++ b/tests/ansible_file_removed_and_added/file_block_removed_and_added.yml
889f2b
@@ -0,0 +1,69 @@
889f2b
+---
889f2b
+
889f2b
+- hosts: all
889f2b
+  vars:
889f2b
+    var_system_crypto_policy: !!str FUTURE
889f2b
+    var_sudo_logfile: !!str /var/log/sudo.log
889f2b
+
889f2b
+  tasks:
889f2b
+    - name: Modify the System Login Banner - add correct banner
889f2b
+      lineinfile:
889f2b
+        dest: /etc/issue
889f2b
+        line: '{{ login_banner_text | regex_replace("^\^(.*)\$$", "\1") | regex_replace("^\((.*)\|.*\)$",
889f2b
+          "\1") | regex_replace("\[\\s\\n\]\+"," ") | regex_replace("\(\?:\[\\n\]\+\|\(\?:\\\\n\)\+\)",
889f2b
+          "\n") | regex_replace("\\", "") | wordwrap() }}'
889f2b
+        create: true
889f2b
+      when: ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
889f2b
+      tags:
889f2b
+        - banner_etc_issue
889f2b
+        - low_complexity
889f2b
+        - medium_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+        - unknown_strategy
889f2b
+
889f2b
+    - name: Test for existence /etc/issue
889f2b
+      stat:
889f2b
+        path: /etc/issue
889f2b
+      register: file_exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
+    - name: Ensure permission 0644 on /etc/issue
889f2b
+      file:
889f2b
+        path: /etc/issue
889f2b
+        mode: '0644'
889f2b
+      when: file_exists.stat is defined and file_exists.stat.exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
+    - block:
889f2b
+
889f2b
+        - name: Remove Rsh Trust Files
889f2b
+          file:
889f2b
+            path: /root/shosts.equiv
889f2b
+            state: absent
889f2b
+
889f2b
+        - name: Add line to /root/shosts.equiv
889f2b
+          lineinfile:
889f2b
+            dest: /root/shosts.equiv
889f2b
+            line: 'test host'
889f2b
+            create: true
889f2b
+      tags:
889f2b
+        - high_severity
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - no_reboot_needed
889f2b
+        - no_rsh_trust_files
889f2b
+        - restrict_strategy
889f2b
+
889f2b
diff --git a/tests/ansible_file_removed_and_added/file_not_removed_and_added.yml b/tests/ansible_file_removed_and_added/file_not_removed_and_added.yml
889f2b
new file mode 100644
889f2b
index 00000000000..3d3e53b958f
889f2b
--- /dev/null
889f2b
+++ b/tests/ansible_file_removed_and_added/file_not_removed_and_added.yml
889f2b
@@ -0,0 +1,49 @@
889f2b
+---
889f2b
+
889f2b
+- hosts: all
889f2b
+  vars:
889f2b
+    var_system_crypto_policy: !!str FUTURE
889f2b
+    var_sudo_logfile: !!str /var/log/sudo.log
889f2b
+
889f2b
+  tasks:
889f2b
+    - name: Modify the System Login Banner - add correct banner
889f2b
+      lineinfile:
889f2b
+        dest: /etc/issue
889f2b
+        line: '{{ login_banner_text | regex_replace("^\^(.*)\$$", "\1") | regex_replace("^\((.*)\|.*\)$",
889f2b
+          "\1") | regex_replace("\[\\s\\n\]\+"," ") | regex_replace("\(\?:\[\\n\]\+\|\(\?:\\\\n\)\+\)",
889f2b
+          "\n") | regex_replace("\\", "") | wordwrap() }}'
889f2b
+        create: true
889f2b
+      when: ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
889f2b
+      tags:
889f2b
+        - banner_etc_issue
889f2b
+        - low_complexity
889f2b
+        - medium_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+        - unknown_strategy
889f2b
+
889f2b
+    - name: Test for existence /etc/issue
889f2b
+      stat:
889f2b
+        path: /etc/issue
889f2b
+      register: file_exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
+    - name: Ensure permission 0644 on /etc/issue
889f2b
+      file:
889f2b
+        path: /etc/issue
889f2b
+        mode: '0644'
889f2b
+      when: file_exists.stat is defined and file_exists.stat.exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
diff --git a/tests/ansible_file_removed_and_added/file_removed_and_added.yml b/tests/ansible_file_removed_and_added/file_removed_and_added.yml
889f2b
new file mode 100644
889f2b
index 00000000000..a44c39a9db2
889f2b
--- /dev/null
889f2b
+++ b/tests/ansible_file_removed_and_added/file_removed_and_added.yml
889f2b
@@ -0,0 +1,62 @@
889f2b
+---
889f2b
+
889f2b
+- hosts: all
889f2b
+  vars:
889f2b
+    var_system_crypto_policy: !!str FUTURE
889f2b
+    var_sudo_logfile: !!str /var/log/sudo.log
889f2b
+
889f2b
+  tasks:
889f2b
+    - name: Modify the System Login Banner - remove incorrect banner
889f2b
+      file:
889f2b
+        state: absent
889f2b
+        path: /etc/issue
889f2b
+      when: ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
889f2b
+      tags:
889f2b
+        - banner_etc_issue
889f2b
+        - low_complexity
889f2b
+        - medium_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+        - unknown_strategy
889f2b
+
889f2b
+    - name: Modify the System Login Banner - add correct banner
889f2b
+      lineinfile:
889f2b
+        dest: /etc/issue
889f2b
+        line: '{{ login_banner_text | regex_replace("^\^(.*)\$$", "\1") | regex_replace("^\((.*)\|.*\)$",
889f2b
+          "\1") | regex_replace("\[\\s\\n\]\+"," ") | regex_replace("\(\?:\[\\n\]\+\|\(\?:\\\\n\)\+\)",
889f2b
+          "\n") | regex_replace("\\", "") | wordwrap() }}'
889f2b
+        create: true
889f2b
+      when: ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
889f2b
+      tags:
889f2b
+        - banner_etc_issue
889f2b
+        - low_complexity
889f2b
+        - medium_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+        - unknown_strategy
889f2b
+
889f2b
+    - name: Test for existence /etc/issue
889f2b
+      stat:
889f2b
+        path: /etc/issue
889f2b
+      register: file_exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
+    - name: Ensure permission 0644 on /etc/issue
889f2b
+      file:
889f2b
+        path: /etc/issue
889f2b
+        mode: '0644'
889f2b
+      when: file_exists.stat is defined and file_exists.stat.exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
diff --git a/tests/ansible_file_removed_and_added/file_removed_and_not_added.yml b/tests/ansible_file_removed_and_added/file_removed_and_not_added.yml
889f2b
new file mode 100644
889f2b
index 00000000000..08cda7e5063
889f2b
--- /dev/null
889f2b
+++ b/tests/ansible_file_removed_and_added/file_removed_and_not_added.yml
889f2b
@@ -0,0 +1,46 @@
889f2b
+---
889f2b
+
889f2b
+- hosts: all
889f2b
+  vars:
889f2b
+    var_system_crypto_policy: !!str FUTURE
889f2b
+    var_sudo_logfile: !!str /var/log/sudo.log
889f2b
+
889f2b
+  tasks:
889f2b
+    - name: Modify the System Login Banner - remove incorrect banner
889f2b
+      file:
889f2b
+        state: absent
889f2b
+        path: /etc/issue
889f2b
+      when: ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
889f2b
+      tags:
889f2b
+        - banner_etc_issue
889f2b
+        - low_complexity
889f2b
+        - medium_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+        - unknown_strategy
889f2b
+
889f2b
+    - name: Test for existence /etc/issue
889f2b
+      stat:
889f2b
+        path: /etc/issue
889f2b
+      register: file_exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
+    - name: Ensure permission 0644 on /etc/issue
889f2b
+      file:
889f2b
+        path: /etc/issue
889f2b
+        mode: '0644'
889f2b
+      when: file_exists.stat is defined and file_exists.stat.exists
889f2b
+      tags:
889f2b
+        - configure_strategy
889f2b
+        - file_permissions_etc_issue
889f2b
+        - low_complexity
889f2b
+        - low_disruption
889f2b
+        - medium_severity
889f2b
+        - no_reboot_needed
889f2b
+
889f2b
diff --git a/tests/test_check_playbook_file_removed_and_added.py b/tests/test_check_playbook_file_removed_and_added.py
889f2b
new file mode 100644
889f2b
index 00000000000..181bb14ed46
889f2b
--- /dev/null
889f2b
+++ b/tests/test_check_playbook_file_removed_and_added.py
889f2b
@@ -0,0 +1,39 @@
889f2b
+import os
889f2b
+import pytest
889f2b
+
889f2b
+from .test_ansible_file_removed_and_added import check_playbook_file_removed_and_added
889f2b
+
889f2b
+
889f2b
+def test_file_removed_and_added():
889f2b
+    playbook_path = os.path.join(os.path.dirname(__file__),
889f2b
+                                 "ansible_file_removed_and_added",
889f2b
+                                 "file_removed_and_added.yml")
889f2b
+    assert not check_playbook_file_removed_and_added(playbook_path)
889f2b
+
889f2b
+
889f2b
+def test_file_removed_and_not_added():
889f2b
+    playbook_path = os.path.join(os.path.dirname(__file__),
889f2b
+                                 "ansible_file_removed_and_added",
889f2b
+                                 "file_removed_and_not_added.yml")
889f2b
+    assert check_playbook_file_removed_and_added(playbook_path)
889f2b
+
889f2b
+
889f2b
+def test_file_not_removed_and_added():
889f2b
+    playbook_path = os.path.join(os.path.dirname(__file__),
889f2b
+                                 "ansible_file_removed_and_added",
889f2b
+                                 "file_not_removed_and_added.yml")
889f2b
+    assert check_playbook_file_removed_and_added(playbook_path)
889f2b
+
889f2b
+
889f2b
+def test_file_block_removed_and_added():
889f2b
+    playbook_path = os.path.join(os.path.dirname(__file__),
889f2b
+                                 "ansible_file_removed_and_added",
889f2b
+                                 "file_block_removed_and_added.yml")
889f2b
+    assert not check_playbook_file_removed_and_added(playbook_path)
889f2b
+
889f2b
+
889f2b
+def test_file_block_removed_and_not_added():
889f2b
+    playbook_path = os.path.join(os.path.dirname(__file__),
889f2b
+                                 "ansible_file_removed_and_added",
889f2b
+                                 "file_block_removed_and_not_added.yml")
889f2b
+    assert check_playbook_file_removed_and_added(playbook_path)
889f2b
889f2b
From 741ec823ac39341f8aa0649031b72d2ac36e8a64 Mon Sep 17 00:00:00 2001
889f2b
From: Watson Sato <wsato@redhat.com>
889f2b
Date: Thu, 12 Aug 2021 10:36:47 +0200
889f2b
Subject: [PATCH 3/3] Mention Ansible static yamlpath test in docs
889f2b
889f2b
---
889f2b
 .../developer/02_building_complianceascode.md      | 14 ++++++++++++++
889f2b
 1 file changed, 14 insertions(+)
889f2b
889f2b
diff --git a/docs/manual/developer/02_building_complianceascode.md b/docs/manual/developer/02_building_complianceascode.md
889f2b
index d536df0a259..87469bf5f9b 100644
889f2b
--- a/docs/manual/developer/02_building_complianceascode.md
889f2b
+++ b/docs/manual/developer/02_building_complianceascode.md
889f2b
@@ -64,6 +64,20 @@ yum install yamllint ansible-lint
889f2b
 apt-get install yamllint ansible-lint
889f2b
 ```
889f2b
 
889f2b
+### Static Ansible Playbooks tests
889f2b
+
889f2b
+Install `yamlpath` and `pytest` to run tests cases that analyse the Ansible
889f2b
+Playbooks' yaml nodes.
889f2b
+```bash
889f2b
+pip3 install yamlpath
889f2b
+
889f2b
+# Fedora/RHEL
889f2b
+yum install python3-pytest
889f2b
+
889f2b
+# Ubuntu/Debian
889f2b
+apt-get install python-pytest
889f2b
+```
889f2b
+
889f2b
 ### Ninja (Faster Builds)
889f2b
 
889f2b
 Install the `ninja` build system if you want to use it instead of