This repository was archived by the owner on Feb 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathevaluate.yml
More file actions
102 lines (90 loc) · 3.04 KB
/
Copy pathevaluate.yml
File metadata and controls
102 lines (90 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
- name: Evaluate the system compliance
hosts: localhost
vars_files:
- ./vars.yaml
vars:
shared_workspace: /tmp
path_to_output: /tmp/evaluate.json
pre_tasks:
- include_tasks: ../tasks/precondition_setup.yml
tasks:
- block:
- name: Check if {{ agent_output }} exists
stat:
path: "{{ agent_output }}"
register: agent_output_stat
- name: Ensure dest directory exists
file:
path: "{{ agent_output_destination }}"
state: directory
mode: '0755'
when: agent_output_stat.stat.exists
- name: Extract {{ agent_output }} if it exists
unarchive:
src: "{{ agent_output }}"
dest: "{{ agent_output_destination }}"
keep_newer: true
when: agent_output_stat.stat.exists
- name: Copy items from extracted directory to extracted directory
copy:
src: "{{ agent_output_destination }}/{{ item }}"
dest: "{{ shared_workspace }}/{{ item }}"
with_items:
- "{{ filename_to_generated_fetcher }}"
- "{{ filename_to_generated_policy }}"
when: agent_output_stat.stat.exists
- name: Run Fetcher
ansible.builtin.command:
argv:
- bash
- "{{ shared_workspace }}/{{ filename_to_generated_fetcher }}"
args:
chdir: "{{ shared_workspace }}"
register: fetcher_result
- name: Run OPA
ansible.builtin.command:
argv:
- opa
- eval
- --data
- "{{ shared_workspace }}/{{ filename_to_generated_policy }}"
- --input
- "{{ shared_workspace }}/{{ filename_to_collected_data }}"
- data.check.result
- --format
- raw
register: checker_result
- name: Set pass/fail based on command result (opa should result 'false' since a fault condition is injected.)
set_fact:
pass_result:
pass: "{{ true if checker_result.stdout == 'false' else false }}"
details: |
[fetcher] cmd: {{ fetcher_result.cmd }}, stdout: {{ fetcher_result.stdout }}, stderr: {{ fetcher_result.stderr }}
[checker] cmd: {{ checker_result.cmd }}, stdout: {{ checker_result.stdout }}, stderr: {{ checker_result.stderr }}
- name: Write pass result to JSON file
copy:
content: "{{ pass_result | to_json }}"
dest: "{{ path_to_output }}"
- name: Pretty print the
debug:
msg: "{{ pass_result }}"
rescue:
- name: Set pass result
set_fact:
pass_result:
pass: false
errors:
- code: "{{ ansible_failed_task.name }}"
message: |
The task "{{ ansible_failed_task.name }}" failed with error:
{{ ansible_failed_result.msg }}
{{ ansible_failed_result.stdout }}
{{ ansible_failed_result.stderr }}
- name: Write pass result to JSON file
copy:
content: "{{ pass_result | to_json }}"
dest: "{{ path_to_output }}"
- name: Pretty print the
debug:
msg: "{{ pass_result }}"