-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print wireguard confdir location for easier debugging
- Loading branch information
Showing
4 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# this is a convenience method to add systemd timers | ||
# | ||
# - name: do dummy timer | ||
# include_role: | ||
# name: basic-host | ||
# tasks_from: add_timer | ||
# vars: | ||
# systemd_timer_name: dummy-timer | ||
# systemd_timer_oncalendar: "*-*-* *:50:00" | ||
# systemd_timer_command: /bin/true | ||
|
||
- set_fact: | ||
systemd_timers: > | ||
{{ {} | combine({ | ||
systemd_timer_name: { | ||
'description': systemd_timer_description|default(systemd_timer_name), | ||
'oncalendar': systemd_timer_oncalendar, | ||
'command': systemd_timer_command|default('/bin/true'), | ||
'add_service': systemd_timer_add_service|default(True), | ||
'user': systemd_timer_user|default('root'), | ||
'randomized_delay_sec': systemd_timer_randomized_delay_sec|default(0), | ||
} | ||
})}} | ||
- name: setup timer | ||
include_tasks: systemd_timer.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# this is a convenience method to delete systemd timers | ||
# | ||
# - name: remove dummy timer | ||
# include_role: | ||
# name: basic-host | ||
# tasks_from: remove_timer | ||
# vars: | ||
# systemd_timer_name: dummy-timer | ||
|
||
- set_fact: | ||
systemd_timers: > | ||
{{ {} | combine({ | ||
systemd_timer_name: { | ||
'state': 'absent', | ||
} | ||
})}} | ||
- name: setup timer | ||
include_tasks: systemd_timer.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# So far this supports simple timers with OnCalendar trigger as cron replacement. | ||
# Eventually it should get expanded to fully support systemd timers, though the | ||
# convenience wrappers might receive less functionality. | ||
# | ||
# The ability to use both a copied script or a command is present in the timer | ||
# file, but not yet supported by this role. If a script is present it should be | ||
# copied, and used as command. | ||
# | ||
# This file is the main entry point for adding more than one timer, and for | ||
# adding host-specific timers through 'systemd_timers' on basic_host run. | ||
# | ||
# For adding/removing a single timer include add_timer or remove_timer. See | ||
# documentation in those files for details. | ||
|
||
- set_fact: | ||
_timer_types: | ||
- timer | ||
- service | ||
|
||
- set_fact: | ||
_timer_types: | ||
- timer | ||
when: | ||
|
||
- name: add systemd timers with service | ||
template: | ||
src: systemd-timer-{{item.0}}.j2 | ||
dest: "/etc/systemd/system/{{item.1}}.{{item.0}}" | ||
mode: 0644 | ||
with_nested: | ||
- ['timer', 'service'] | ||
- "{{systemd_timers}}" | ||
when: > | ||
(systemd_timers[item.1].state is undefined or | ||
(systemd_timers[item.1].state is defined and systemd_timers[item.1].state != "absent")) and | ||
(systemd_timers[item.1].add_service is undefined or | ||
(systemd_timers[item.1].add_service is defined and systemd_timers[item.1].add_service != False)) | ||
# this could be written simpler, but to make it easier for future changes it's | ||
# intentionally written as the above one | ||
- name: add systemd timers without service | ||
template: | ||
src: systemd-timer-{{item.0}}.j2 | ||
dest: "/etc/systemd/system/{{item.1}}.{{item.0}}" | ||
mode: 0644 | ||
with_nested: | ||
- ['timer'] | ||
- "{{systemd_timers}}" | ||
when: > | ||
(systemd_timers[item.1].state is undefined or | ||
(systemd_timers[item.1].state is defined and systemd_timers[item.1].state != "absent")) and | ||
(systemd_timers[item.1].add_service is defined and systemd_timers[item.1].add_service == False) | ||
- name: enable timer | ||
systemd: | ||
daemon_reload: yes | ||
name: "{{item.key}}.timer" | ||
state: started | ||
enabled: yes | ||
with_dict: "{{systemd_timers}}" | ||
when: > | ||
(item.value.state is undefined or | ||
(item.value.state is defined and item.value.state != "absent")) | ||
- name: disable timer | ||
systemd: | ||
daemon_reload: yes | ||
name: "{{item.key}}.timer" | ||
state: stopped | ||
enabled: no | ||
with_dict: "{{systemd_timers}}" | ||
# on re-runs timers might already have been removed and can't be disabled: | ||
# ignore errors | ||
ignore_errors: True | ||
when: > | ||
item.value.state is defined and item.value.state == "absent" | ||
- name: remove systemd timers | ||
file: | ||
path: /etc/systemd/system/{{item.1}}.{{item.0}} | ||
state: absent | ||
with_nested: | ||
- ['timer', 'service'] | ||
- "{{systemd_timers}}" | ||
when: > | ||
systemd_timers[item.1].state is defined and systemd_timers[item.1].state == "absent" |