diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..ede6ea2f4fcca3eb6f9d0a8f37fa4014280e9f51 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,41 @@ +--- +--- +- block: + + - name: Failing when timer_command is undefined + fail: + msg: Varible timer_command is not defined + when: item.value.timer_command is undefined + with_dict: "{{ timers }}" + + - name: Uploading service file + template: + src: service.j2 + dest: "{{ systemd_base_path | default('/etc/systemd/system') }}/{{ item.key }}.service" + owner: "{{ item.value.timer_user | default('root') }}" + group: "{{ item.value.timer_user | default('root') }}" + mode: 0644 + with_dict: "{{ timers }}" + notify: Reload systemd + + - name: Uploading timer file + template: + src: timer.j2 + dest: "{{ systemd_base_path | default('/etc/systemd/system') }}/{{ item.key }}.timer" + owner: "{{ item.value.timer_user | default('root') }}" + group: "{{ item.value.timer_user | default('root') }}" + mode: 0644 + with_dict: "{{ timers }}" + notify: Reload systemd + + - name: Enabling timers + systemd: + name: "{{ item.key }}.timer" + state: restarted + enabled: true + masked: false + daemon_reload: true + scope: "{{ systemd_scope | default('system') }}" + with_dict: "{{ timers }}" + + when: timers is defined \ No newline at end of file diff --git a/templates/timer.j2 b/templates/timer.j2 new file mode 100644 index 0000000000000000000000000000000000000000..c7c8b0b926e32dc7be75741841bf64a15194ba73 --- /dev/null +++ b/templates/timer.j2 @@ -0,0 +1,27 @@ +[Unit] +Description={{ item.key }} Timer + +[Timer] +{% if item.value.timer_OnActiveSec is defined %} +OnActiveSec={{ item.value.timer_OnActiveSec }} +{% endif %} +{% if item.value.timer_OnBootSec is defined %} +OnBootSec={{ item.value.timer_OnBootSec }} +{% endif %} +{% if item.value.timer_OnStartupSec is defined %} +OnStartupSec={{ item.value.timer_OnStartupSec }} +{% endif %} +{% if item.value.timer_OnUnitActiveSec is defined %} +OnUnitActiveSec={{ item.value.timer_OnUnitActiveSec }} +{% endif %} +{% if item.value.timer_OnUnitInactiveSec is defined %} +OnUnitInactiveSec={{ item.value.timer_OnUnitInactiveSec }} +{% endif %} +{% if item.value.timer_OnCalendar is defined %} +OnCalendar={{ item.value.timer_OnCalendar }} +Persistent={{ item.value.timer_persistent | default('false') }} +{% endif %} +AccuracySec={{ item.value.timer_AccuracySec | default('15s') }} + +[Install] +WantedBy=timers.target \ No newline at end of file