Skip to content

Commit

Permalink
Print wireguard confdir location for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bwachter committed Feb 29, 2024
1 parent a7a139e commit d5f9132
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tasks/_manage_wireguard_install.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- set_fact:
_wg_installed: true

- name: make sure wireguard configuration directory exists
- name: make sure wireguard configuration directory exists ({{_wireguard_confdir}})
ansible.builtin.file:
path: "{{_wireguard_confdir}}"
owner: root
Expand Down
26 changes: 26 additions & 0 deletions tasks/add_systemd_timer.yml
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
19 changes: 19 additions & 0 deletions tasks/remove_systemd_timer.yml
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
86 changes: 86 additions & 0 deletions tasks/systemd_timer.yml
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"

0 comments on commit d5f9132

Please sign in to comment.