ansible-collection/roles/cron_healthcheck_script/tasks/healthcheck.yml
GregoryDosh 60e5de9e8d
All checks were successful
Update Version / Update Version (push) Successful in 10s
refactor: rename vars to be more like they were
2024-12-21 12:45:12 -06:00

67 lines
2.4 KiB
YAML

# Ansible Roles for managing Auengun.net Infrastructure & Testing/Learning.
# Source available at git.auengun.net/homelab/ansible-collection
# Copyright (C) 2023 GregoryDosh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-FileCopyrightText: 2023 GregoryDosh
---
- name: Create/Update with Healthcheck API
ansible.builtin.uri:
url: "{{ HEALTHCHECK_SITE_URL }}"
method: POST
body_format: json
status_code: [200, 201]
return_content: true
headers:
Content-Type: application/json
X-Api-Key: "{{ HEALTHCHECK_SITE_API_KEY }}"
body: |
{
"name": "{{ HEALTHCHECK_NAME }}",
"schedule": "{{ HEALTHCHECK_SCHEDULE }}",
"tz": "{{ HEALTHCHECK_SCHEDULE_TZ }}",
"grace": {{ HEALTHCHECK_GRACE }},
"tags": "{{ HEALTHCHECK_TAGS }}",
"unique": [
"name"
]
}
register: healtcheck_api_response
- name: Set Ping URL for script from JSON API response
ansible.builtin.set_fact:
_hc_ping_url: "{{ healtcheck_api_response.json.ping_url }}"
- name: template healthcheck.sh.j2 into destination
become: true
ansible.builtin.template:
src: "{{ role_path }}/templates/healthcheck.sh.j2"
dest: "{{ HEALTHCHECK_FILE_BASEPATH }}/{{ HEALTHCHECK_FILE_NAME }}"
owner: "{{ HEALTHCHECK_FILE_USER }}"
group: "{{ HEALTHCHECK_FILE_GROUP }}"
mode: "{{ HEALTHCHECK_FILE_MODE }}"
- name: create crontab entry
become: true
ansible.builtin.cron:
user: "{{ HEALTHCHECK_CRON_USER }}"
name: "{{ HEALTHCHECK_NAME }}"
minute: "{{ HEALTHCHECK_CRON_MINUTE }}"
hour: "{{ HEALTHCHECK_CRON_HOUR }}"
day: "{{ HEALTHCHECK_CRON_DAY }}"
month: "{{ HEALTHCHECK_CRON_MONTH }}"
weekday: "{{ HEALTHCHECK_CRON_WEEKDAY }}"
job: "{{ HEALTHCHECK_FILE_BASEPATH }}/{{ HEALTHCHECK_FILE_NAME }}"