Skip to content

Commit 7083c01

Browse files
author
Wolfgang Hotwagner
committed
initial commit
0 parents  commit 7083c01

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Ansible-Role: atb-ansible-healthcheck
2+
3+
Installs a client-script for the vulnerable healthcheckd service.
4+
5+
6+
## Requirements
7+
8+
- Debian or Ubuntu
9+
10+
## Role Variables
11+
12+
```yaml
13+
healthcheck_status: "OK"
14+
healthcheck_wrapper_path: "/usr/local/bin"
15+
healthcheck_wrapper_mode: "0755"
16+
```
17+
18+
## Example Playbook
19+
20+
```yaml
21+
- hosts: localhost
22+
roles:
23+
vars:
24+
healthcheck_wrapper_path: "/media/health"
25+
healthcheck_wrapper_mode: "0777"
26+
healthcheck_server: 192.168.100.23
27+
```
28+
29+
## License
30+
31+
GPL-3.0
32+
33+
## Author
34+
35+
- Wolfgang Hotwagner

defaults/main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# defaults file for atb-ansible-healthcheck
3+
healthcheck_status: "OK"
4+
healthcheck_wrapper_path: "/usr/local/bin"
5+
healthcheck_wrapper_mode: "0755"

files/healthcheck

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
import socket
4+
from sys import argv
5+
6+
target_port = 1881
7+
8+
if len(argv) < 3 or len(argv) > 4 :
9+
print(f"usage: {argv[0]} <host> <status> [<port>]")
10+
exit(1)
11+
12+
target_host = argv[1]
13+
14+
if len(argv) == 4:
15+
target_port = argv[3]
16+
17+
host = socket.gethostname().encode() + b'\r\n'
18+
status = argv[2].encode() + b'\r\n'
19+
20+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
21+
s.connect((target_host, target_port))
22+
data = s.recv(1024)
23+
s.sendall(host)
24+
data = s.recv(1024)
25+
s.sendall(status)
26+
27+
exit(0)

meta/main.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
galaxy_info:
2+
author: Wolfgang Hotwagner
3+
description: Installs a client-script for the vulnerable healthcheckd service.
4+
company: Austrian Institute of Technology
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
# Choose a valid license ID from https://spdx.org - some suggested licenses:
11+
# - BSD-3-Clause (default)
12+
# - MIT
13+
# - GPL-2.0-or-later
14+
# - GPL-3.0-only
15+
# - Apache-2.0
16+
# - CC-BY-4.0
17+
license: GPL-3.0-only
18+
19+
min_ansible_version: 2.1
20+
21+
# If this a Container Enabled role, provide the minimum Ansible Container version.
22+
# min_ansible_container_version:
23+
24+
#
25+
# Provide a list of supported platforms, and for each platform a list of versions.
26+
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
27+
# To view available platforms and versions (or releases), visit:
28+
# https://galaxy.ansible.com/api/v1/platforms/
29+
#
30+
# platforms:
31+
# - name: Fedora
32+
# versions:
33+
# - all
34+
# - 25
35+
# - name: SomePlatform
36+
# versions:
37+
# - all
38+
# - 1.0
39+
# - 7
40+
# - 99.99
41+
42+
galaxy_tags: []
43+
# List tags for your role here, one per line. A tag is a keyword that describes
44+
# and categorizes the role. Users find roles by searching for tags. Be sure to
45+
# remove the '[]' above, if you add tags to this list.
46+
#
47+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
48+
# Maximum 20 tags per role.
49+
50+
dependencies: []
51+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
52+
# if you add dependencies to this list.

tasks/main.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# tasks file for atb-ansible-healthcheck
2+
- name: ensure cron installed
3+
ansible.builtin.apt:
4+
name: cron
5+
update_cache: true
6+
7+
- name: deploy healthcheck script
8+
ansible.builtin.copy:
9+
src: healthcheck
10+
dest: /usr/local/bin/healthcheck
11+
owner: root
12+
group: root
13+
mode: 0755
14+
15+
- name: create destination directory
16+
ansible.builtin.file:
17+
path: "{{healthcheck_wrapper_path}}"
18+
state: directory
19+
recurse: yes
20+
21+
- name: deploy cron-wrapper
22+
ansible.builtin.template:
23+
src: wrapper.j2
24+
dest: "{{healthcheck_wrapper_path}}/healthcheck_cron.sh"
25+
owner: root
26+
group: root
27+
mode: "{{healthcheck_wrapper_mode}}"
28+
29+
- name: Create cron-job
30+
ansible.builtin.cron:
31+
name: "healthcheck"
32+
job: "{{healthcheck_wrapper_path}}/healthcheck_cron.sh"
33+
minute: "*/10"

templates/wrapper.j2

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
/usr/local/bin/healthcheck {{ healthcheck_server }} {{ healthcheck_status }}

0 commit comments

Comments
 (0)