|
25 | 25 | - name: Run role |
26 | 26 | include_tasks: tasks/run_role_with_clear_facts.yml |
27 | 27 | vars: |
| 28 | + __ssh_write_log_file: true |
28 | 29 | __sr_public: true |
29 | 30 |
|
30 | | - # look for the exact module invocation, not some other message that might contain the string |
31 | | - - name: Check system journal contains role fingerprints |
| 31 | + - name: Get fingerprint entries from journal |
32 | 32 | ansible.builtin.shell: |
33 | 33 | executable: /bin/bash |
34 | 34 | cmd: >- |
35 | 35 | set -eo pipefail; |
36 | 36 | journalctl --since "{{ __journal_start_time }}" --no-pager | |
37 | | - grep -v " Invoked with" | grep "sr_fingerprint.*begin system_role:ssh" || |
38 | | - { echo ERROR: BEGIN fingerprint not found; exit 1; }; |
39 | | - journalctl --since "{{ __journal_start_time }}" --no-pager | |
40 | | - grep -v " Invoked with" | grep "sr_fingerprint.*success system_role:ssh" || |
41 | | - { echo ERROR: SUCCESS fingerprint not found; exit 1; } |
| 37 | + grep -v " Invoked with" | |
| 38 | + grep "sr_fingerprint.*role_name=ssh" |
| 39 | + register: __register_journal_fingerprints |
42 | 40 | changed_when: false |
43 | 41 | when: __register_dev_log.stat.exists |
44 | 42 |
|
| 43 | + - name: Check that the log file was written |
| 44 | + ansible.builtin.slurp: |
| 45 | + path: /var/log/sysroles.jsonl |
| 46 | + register: __register_log_file |
| 47 | + |
| 48 | + - name: Verify log file and journal fingerprints |
| 49 | + when: __register_dev_log.stat.exists |
| 50 | + vars: |
| 51 | + __journal_lines: "{{ __register_journal_fingerprints.stdout_lines }}" |
| 52 | + __journal_begin: "{{ __journal_lines | select('search', 'status=begin') | list }}" |
| 53 | + __journal_success: "{{ __journal_lines | select('search', 'status=success') | list }}" |
| 54 | + __begin_date: "{{ (__journal_begin[0] | regex_search('date=([^ ]+)', '\\1'))[0] }}" |
| 55 | + __success_date: "{{ (__journal_success[0] | regex_search('date=([^ ]+)', '\\1'))[0] }}" |
| 56 | + __file_content: "{{ __register_log_file.content | b64decode }}" |
| 57 | + block: |
| 58 | + - name: Print contents of logs |
| 59 | + debug: |
| 60 | + var: item |
| 61 | + loop: |
| 62 | + - "{{ __file_content }}" |
| 63 | + - "{{ __journal_lines }}" |
| 64 | + |
| 65 | + - name: Assert content is correct |
| 66 | + ansible.builtin.assert: |
| 67 | + that: |
| 68 | + - __journal_begin | length > 0 |
| 69 | + - __journal_success | length > 0 |
| 70 | + - __begin_date in __file_content |
| 71 | + - __success_date in __file_content |
| 72 | + |
45 | 73 | - name: Restore configuration files |
46 | 74 | hosts: all |
47 | 75 | vars: |
|
0 commit comments