mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-18 17:05:13 +00:00
Feature: Add a fingerprint string to the system log to indicate when the role began successfully, and when the role finished successfully. The fingerprint string indicates the role name, a timestamp, and the platform. Reason: Users can see when the role was used and if it was used successfully. This information from the system log can be collected by log scanners and aggregators for further analysis. Result: The role logs fingerprints to the system log. This also adds a test to check if the fingerprints were written upon a successful role invocation. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
46 lines
1.9 KiB
YAML
46 lines
1.9 KiB
YAML
# SPDX-License-Identifier: BSD-3-Clause
|
|
---
|
|
- name: Test executing the role with default parameters
|
|
hosts: all
|
|
tasks:
|
|
- name: See if /dev/log exists for the fingerprint check
|
|
ansible.builtin.stat:
|
|
path: /dev/log
|
|
register: __register_dev_log
|
|
|
|
- name: Set the start time for the journal search
|
|
ansible.builtin.set_fact:
|
|
__journal_start_time: "{{ ansible_facts['date_time']['date'] ~ ' ' ~ ansible_facts['date_time']['time'] }}"
|
|
when: __register_dev_log.stat.exists
|
|
|
|
- name: Include the task 'el_repo_setup.yml'
|
|
include_tasks: tasks/el_repo_setup.yml
|
|
|
|
- name: Run role with clear facts
|
|
include_tasks: tasks/run_role_with_clear_facts.yml
|
|
|
|
# look for the exact module invocation, not some other message that might contain the string
|
|
- name: Check system journal contains role fingerprints
|
|
ansible.builtin.shell:
|
|
executable: /bin/bash
|
|
cmd: >-
|
|
set -eo pipefail;
|
|
journalctl --since "{{ __journal_start_time }}" --no-pager |
|
|
grep -v " Invoked with" | grep "sr_fingerprint.*begin system_role:network" ||
|
|
{ echo ERROR: BEGIN fingerprint not found; exit 1; };
|
|
journalctl --since "{{ __journal_start_time }}" --no-pager |
|
|
grep -v " Invoked with" | grep "sr_fingerprint.*success system_role:network" ||
|
|
{ echo ERROR: SUCCESS fingerprint not found; exit 1; }
|
|
changed_when: false
|
|
when: __register_dev_log.stat.exists
|
|
|
|
# module_warning - see https://github.com/ansible/ansible/issues/85394
|
|
- name: Test warning and info logs
|
|
assert:
|
|
that:
|
|
- "'warnings' not in __network_connections_result or
|
|
__network_connections_result.warnings | reject('match', module_warning ~ '$') | list | length == 0"
|
|
msg: "There are warnings"
|
|
vars:
|
|
module_warning: >-
|
|
Error loading plugin 'ansible.netcommon.network': No module named 'ansible_collections.ansible.netcommon'
|