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

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