Skip to content

Commit

Permalink
Add tests/tasks/assert_files_identical.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrosi committed May 20, 2024
1 parent 7539fb6 commit c3bff30
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 70 deletions.
18 changes: 18 additions & 0 deletions tests/tasks/assert_files_identical.yml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 10 additions & 28 deletions tests/tests_large_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 10 additions & 28 deletions tests/tests_multiple_sudoers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 4 additions & 14 deletions tests/tests_role_applied.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c3bff30

Please sign in to comment.