migrate
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
---
|
||||
- name: Docker healthcheck audit
|
||||
hosts: all
|
||||
become: true
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Collect Docker containers
|
||||
community.docker.docker_host_info:
|
||||
containers: true
|
||||
register: docker_host_info
|
||||
|
||||
- name: Build list of containers missing healthcheck
|
||||
ansible.builtin.set_fact:
|
||||
containers_missing_healthcheck: "{{ (containers_missing_healthcheck | default([])) + [item.Names[0] | default(item.Id)] }}"
|
||||
when:
|
||||
- item.Config is defined
|
||||
- item.Config.Healthcheck is not defined
|
||||
loop: "{{ docker_host_info.containers | default([]) }}"
|
||||
|
||||
- name: Ensure missing-healthcheck list exists
|
||||
ansible.builtin.set_fact:
|
||||
containers_missing_healthcheck: []
|
||||
when: containers_missing_healthcheck is not defined
|
||||
|
||||
- name: Build audit report
|
||||
ansible.builtin.set_fact:
|
||||
docker_healthcheck_audit_report:
|
||||
checked_containers: "{{ docker_host_info.containers | default([]) | length }}"
|
||||
missing_healthcheck_count: "{{ containers_missing_healthcheck | length }}"
|
||||
missing_healthcheck_containers: "{{ containers_missing_healthcheck }}"
|
||||
|
||||
- name: Save healthcheck audit report
|
||||
ansible.builtin.copy:
|
||||
dest: "<< audit_report_path | default('/tmp/docker-healthcheck-audit.json') >>"
|
||||
content: "{{ docker_healthcheck_audit_report | to_nice_json }}"
|
||||
mode: "0640"
|
||||
when: audit_save_report | default(true)
|
||||
|
||||
- name: Print audit summary
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
Checked {{ docker_healthcheck_audit_report.checked_containers }} containers,
|
||||
found {{ docker_healthcheck_audit_report.missing_healthcheck_count }} without healthcheck.
|
||||
|
||||
- name: Fail when missing healthchecks are found
|
||||
ansible.builtin.fail:
|
||||
msg: "Containers missing healthcheck: {{ containers_missing_healthcheck | join(', ') }}"
|
||||
when:
|
||||
- audit_fail_on_missing | default(false)
|
||||
- containers_missing_healthcheck | length > 0
|
||||
@@ -0,0 +1,2 @@
|
||||
collections:
|
||||
- name: community.docker
|
||||
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"slug": "docker-healthcheck-audit",
|
||||
"kind": "ansible",
|
||||
"metadata": {
|
||||
"name": "Docker Healthcheck Audit",
|
||||
"description": "Audits Docker containers for missing healthchecks and optionally fails the playbook when violations are found. Can save a JSON audit report to the target host.",
|
||||
"tags": [
|
||||
"docker",
|
||||
"audit",
|
||||
"healthcheck",
|
||||
"compliance"
|
||||
],
|
||||
"icon": {
|
||||
"provider": "mdi",
|
||||
"id": "stethoscope",
|
||||
"color": "blue"
|
||||
},
|
||||
"draft": false,
|
||||
"version": {
|
||||
"name": "1",
|
||||
"source_dep_name": "manual/docker-healthcheck-audit"
|
||||
}
|
||||
},
|
||||
"variables": [
|
||||
{
|
||||
"title": "Audit",
|
||||
"name": "audit",
|
||||
"items": [
|
||||
{
|
||||
"name": "audit_fail_on_missing",
|
||||
"type": "bool",
|
||||
"title": "Fail Missing Checks",
|
||||
"required": false,
|
||||
"default": false,
|
||||
"description": "Fail the play if one or more containers are missing a healthcheck"
|
||||
},
|
||||
{
|
||||
"name": "audit_save_report",
|
||||
"type": "bool",
|
||||
"title": "Save JSON Report",
|
||||
"required": false,
|
||||
"default": true,
|
||||
"description": "Save audit report to a JSON file on the target host"
|
||||
},
|
||||
{
|
||||
"name": "audit_report_path",
|
||||
"type": "str",
|
||||
"title": "Audit Report Path",
|
||||
"required": false,
|
||||
"default": "/tmp/docker-healthcheck-audit.json",
|
||||
"description": "Path to store the generated JSON report",
|
||||
"config": {
|
||||
"placeholder": "/tmp/docker-healthcheck-audit.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Internal",
|
||||
"name": "internal",
|
||||
"items": [
|
||||
{
|
||||
"name": "containers_missing_healthcheck",
|
||||
"type": "str",
|
||||
"title": "Containers Missing Healthcheck",
|
||||
"required": false,
|
||||
"default": ""
|
||||
},
|
||||
{
|
||||
"name": "docker_healthcheck_audit_report",
|
||||
"type": "str",
|
||||
"title": "Healthcheck Audit Report",
|
||||
"required": false,
|
||||
"default": ""
|
||||
},
|
||||
{
|
||||
"name": "docker_host_info",
|
||||
"type": "str",
|
||||
"title": "Docker Host Info",
|
||||
"required": false,
|
||||
"default": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user