-
Notifications
You must be signed in to change notification settings - Fork 0
/
ara_report.yml
59 lines (50 loc) · 1.72 KB
/
ara_report.yml
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
---
- name: 'Send ARA report'
hosts: 'all'
gather_facts: false
become: false
connection: 'local'
tasks:
- name: 'Generate report'
delegate_to: 'localhost'
run_once: true
check_mode: false
block:
- name: 'Get ARA playbook ID'
ara_playbook:
changed_when: false
register: 'ara_info'
- name: Recover base url from ara
set_fact:
ara_base_url: "{{ lookup('ara_api', '/api/') }}"
changed_when: false
- name: 'Generate report'
ansible.builtin.copy:
dest: "{{ ara_report_location }}"
mode: '0644'
content: |
Hi there,
The report for this run is available in ARA:
{{ ara_report_url | default(ara_base_url['api'][0], true) | regex_replace('/api/v1/', '/playbooks') }}/{{ ara_info['playbook']['id'] }}.html
Cheers!
Ansible & ARA
changed_when: false
- name: 'Send email using mail'
ansible.builtin.shell: |
set -o pipefail
cat {{ ara_report_location }} | mail -s "Ansible run report: {{ ara_playbook_name }}" {{ ara_report_mail }}
args:
executable: '/bin/bash'
changed_when: false
rescue:
- name: 'Error generating ARA report'
ansible.builtin.debug:
msg: |
An error occurred when generating the report, either the ARA server was
unavailable during this time, or sending the email failed.
always:
- name: 'Remove report file'
ansible.builtin.file:
path: "{{ ara_report_location }}"
state: 'absent'
changed_when: false