Skip to content

Commit bc28e87

Browse files
committed
Add systemd service and timer
1 parent 4c45b9f commit bc28e87

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

tasks/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@
4242
path: /etc/cron.d/ansible-drift
4343
state: absent
4444

45+
- name: Copy systemd service and timer configs
46+
ansible.builtin.template:
47+
dest: "/etc/systemd/system/{{ item }}"
48+
mode: "0644"
49+
src: "systemd/{{ item }}.j2"
50+
loop:
51+
- ansible-drift.service
52+
- ansible-drift.timer
53+
when: drift_playbook|d()
54+
55+
- name: Enable systemd timer
56+
ansible.builtin.systemd_service:
57+
daemon_reload: true
58+
enabled: true
59+
name: ansible-drift.timer
60+
state: started
61+
when:
62+
- drift_playbook|d()
63+
- not ansible_check_mode
64+
4565
- name: Make sure we have .gnupg dir
4666
ansible.builtin.file:
4767
path: /home/{{ drift_user }}/.gnupg
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
After=network-online.target
3+
Description=ansible-drift
4+
Wants=network-online.target
5+
6+
[Service]
7+
ExecStart=/usr/local/bin/ansible-drift {{ drift_playbook }}
8+
Type=simple
9+
User={{ drift_user }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=ansible-drift
3+
4+
[Timer]
5+
OnCalendar=*-*-* 05:00:00
6+
Persistent=True
7+
8+
[Install]
9+
WantedBy=timers.target

0 commit comments

Comments
 (0)