ansible-pull(role): make successful run timestamp exporter work
The successful run timestamp exporter didn't work, because the ansible-pull user wouldn't necessarily have the necessary permissions and because the command wouldn't properly work. Move the timestamp export as well as the reboot to separate services, which always run as root, to ensure these operations work and to have a clean setup using systemd services. Also move the successful run timestamp exporter to a custom script to have it work properly.
This commit is contained in:
parent
f6f6cc4804
commit
1157c98ff5
3 changed files with 49 additions and 4 deletions
8
roles/ansible_pull/files/ansible-pull-reboot.service
Normal file
8
roles/ansible_pull/files/ansible-pull-reboot.service
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=ansible-pull reboot, if required
|
||||
After=ansible-pull.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
# Reboot, if /var/run/reboot-required or /var/run/ansible-reboot-required exist.
|
||||
ExecStart=/usr/bin/bash -c 'if [ -e /var/run/reboot-required ] || [ -e /var/run/ansible-reboot-required ]; then systemctl reboot; fi'
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=ansible-pull successful run timestamp exporter
|
||||
After=ansible-pull.service
|
||||
Before=ansible-pull-reboot.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=ansible-pull-successful-run-timestamp-exporter
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
echo "ansible_pull_last_successful_run_timestamp_seconds $(date +%s)" > /var/lib/node_exporter_textfile/ansible_pull.prom.$$
|
||||
mv /var/lib/node_exporter_textfile/ansible_pull.prom.$$ /var/lib/node_exporter_textfile/ansible_pull.prom
|
||||
Loading…
Reference in a new issue