Add service to start offlineimap on linux automatically
This commit is contained in:
4
roles/offlineimap/handlers/main.yml
Normal file
4
roles/offlineimap/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: Reload systemd-units
|
||||
become: yes
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
20
roles/offlineimap/tasks/main.yml
Normal file
20
roles/offlineimap/tasks/main.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
- name: Ensure systemd-creds for offlineimap
|
||||
become: yes
|
||||
community.general.systemd_creds_encrypt:
|
||||
name: enpass-password
|
||||
secret: "{{ enpass_password }}"
|
||||
register: encrypted_enpass_password
|
||||
|
||||
- name: Ensure systemd service file for offlineimap
|
||||
become: yes
|
||||
template:
|
||||
src: offlineimap.service.j2
|
||||
dest: /lib/systemd/system/offlineimap.service
|
||||
notify: Reload systemd-units
|
||||
|
||||
- name: Ensure offlineimap service is running
|
||||
become: yes
|
||||
service:
|
||||
name: offlineimap
|
||||
state: started
|
||||
enabled: yes
|
||||
10
roles/offlineimap/templates/offlineimap.service.j2
Normal file
10
roles/offlineimap/templates/offlineimap.service.j2
Normal file
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Run offlineimap in the background for {{ ansible_user_id }}
|
||||
|
||||
[Service]
|
||||
User={{ ansible_user_id }}
|
||||
SetCredentialEncrypted=enpass-password: {{ encrypted_enpass_password.value | replace("\n", " ") }}
|
||||
ExecStart=bash -c 'source ~/.profile && MASTERPW="$(systemd-creds cat enpass-password)" ~/.local/bin/offlineimap'
|
||||
|
||||
[Install]
|
||||
WantedBy=graphical.target
|
||||
Reference in New Issue
Block a user