From c3bff309dd9a3a4b94c7eae28828c1c6aba81aaf Mon Sep 17 00:00:00 2001 From: Sergei Petrosian Date: Mon, 20 May 2024 16:50:30 +0200 Subject: [PATCH] Add tests/tasks/assert_files_identical.yml --- tests/tasks/assert_files_identical.yml | 18 ++++++++++++ tests/tests_large_configuration.yml | 38 +++++++------------------- tests/tests_multiple_sudoers.yml | 38 +++++++------------------- tests/tests_role_applied.yml | 18 +++--------- 4 files changed, 42 insertions(+), 70 deletions(-) create mode 100644 tests/tasks/assert_files_identical.yml diff --git a/tests/tasks/assert_files_identical.yml b/tests/tasks/assert_files_identical.yml new file mode 100644 index 0000000..ebf4bdb --- /dev/null +++ b/tests/tasks/assert_files_identical.yml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: MIT +--- +- name: Get stat of {{ __sudo_ok_path }} + delegate_to: localhost + stat: + path: "{{ __sudo_ok_path }}" + checksum_algorithm: sha256 + register: __ok_path_stat + +- name: Get stat of {{ __sudo_test_path }} + stat: + path: "{{ __sudo_test_path }}" + checksum_algorithm: sha256 + register: __test_path_stat + +- name: Assert that files are identical + assert: + that: __ok_path_stat.stat.checksum == __test_path_stat.stat.checksum diff --git a/tests/tests_large_configuration.yml b/tests/tests_large_configuration.yml index 9a6a763..3ce46c9 100644 --- a/tests/tests_large_configuration.yml +++ b/tests/tests_large_configuration.yml @@ -181,40 +181,22 @@ register: sudoers_ok - name: Check sudoers - shell: >- - echo "{{ sudoers_ok.stat.checksum }} /etc/sudoers" | - sha256sum --check - changed_when: false - - - name: Get stat of {{ ok_path }} - delegate_to: localhost + include_tasks: tasks/assert_files_identical.yml vars: - ok_path: files/tests_large_configuration_pingers.ok - stat: - path: "{{ ok_path }}" - checksum_algorithm: sha256 - register: pingers_ok + __sudo_ok_path: files/tests_large_configuration_sudoers.ok + __sudo_test_path: /etc/sudoers - name: Check pingers - shell: >- - echo "{{ pingers_ok.stat.checksum }} /etc/sudoers.d/pingers" | - sha256sum --check - changed_when: false - - - name: Get stat of {{ ok_path }} - delegate_to: localhost + include_tasks: tasks/assert_files_identical.yml vars: - ok_path: files/tests_large_configuration_root.ok - stat: - path: "{{ ok_path }}" - checksum_algorithm: sha256 - register: root_ok + __sudo_ok_path: files/tests_large_configuration_pingers.ok + __sudo_test_path: /etc/sudoers.d/pingers - name: Check root - shell: >- - echo "{{ root_ok.stat.checksum }} /etc/sudoers.d/root" | - sha256sum --check - changed_when: false + include_tasks: tasks/assert_files_identical.yml + vars: + __sudo_ok_path: files/tests_large_configuration_root.ok + __sudo_test_path: /etc/sudoers.d/root - name: Restore sudoers copy: diff --git a/tests/tests_multiple_sudoers.yml b/tests/tests_multiple_sudoers.yml index 31309bd..0907bca 100644 --- a/tests/tests_multiple_sudoers.yml +++ b/tests/tests_multiple_sudoers.yml @@ -133,40 +133,22 @@ register: sudoers_ok - name: Check sudoers - shell: >- - echo "{{ sudoers_ok.stat.checksum }} /etc/sudoers" | - sha256sum --check - changed_when: false - - - name: Get stat of {{ ok_path }} - delegate_to: localhost + include_tasks: tasks/assert_files_identical.yml vars: - ok_path: files/tests_multiple_sudoers_pingers.ok - stat: - path: "{{ ok_path }}" - checksum_algorithm: sha256 - register: pingers_ok + __sudo_ok_path: files/tests_multiple_sudoers_sudoers.ok + __sudo_test_path: /etc/sudoers - name: Check pingers - shell: >- - echo "{{ pingers_ok.stat.checksum }} /etc/sudoers.d/pingers" | - sha256sum --check - changed_when: false - - - name: Get stat of {{ ok_path }} - delegate_to: localhost + include_tasks: tasks/assert_files_identical.yml vars: - ok_path: files/tests_multiple_sudoers_root.ok - stat: - path: "{{ ok_path }}" - checksum_algorithm: sha256 - register: root_ok + __sudo_ok_path: files/tests_multiple_sudoers_pingers.ok + __sudo_test_path: /etc/sudoers.d/pingers - name: Check root - shell: >- - echo "{{ root_ok.stat.checksum }} /etc/sudoers.d/root" | - sha256sum --check - changed_when: false + include_tasks: tasks/assert_files_identical.yml + vars: + __sudo_ok_path: files/tests_multiple_sudoers_root.ok + __sudo_test_path: /etc/sudoers.d/root - name: Restore sudoers copy: diff --git a/tests/tests_role_applied.yml b/tests/tests_role_applied.yml index 571c76d..c1a7e81 100644 --- a/tests/tests_role_applied.yml +++ b/tests/tests_role_applied.yml @@ -36,21 +36,11 @@ mode: 0644 remote_src: true - - name: Get stat of {{ ok_path }} - delegate_to: localhost - vars: - ok_path: files/tests_role_applied.ok - stat: - path: "{{ ok_path }}" - checksum_algorithm: sha256 - register: sudoers_ok - - # sha256sum ./files/test_role_applied.ok - name: Check sudoers - shell: >- - echo "{{ sudoers_ok.stat.checksum }} /etc/sudoers" | - sha256sum --check - changed_when: false + include_tasks: tasks/assert_files_identical.yml + vars: + __sudo_ok_path: files/tests_role_applied.ok + __sudo_test_path: /etc/sudoers - name: Restore sudoers copy: