diff --git a/roles/himawaripy/tasks/main.yml b/roles/himawaripy/tasks/main.yml index b46f348..0f70974 100644 --- a/roles/himawaripy/tasks/main.yml +++ b/roles/himawaripy/tasks/main.yml @@ -10,32 +10,40 @@ state=link - name: Push himawaripy service file - template: src=himawaripy.service.j2 dest=/etc/systemd/system/himawaripy@.service + template: src=himawaripy.service.j2 dest=/etc/systemd/user/himawaripy.service notify: - reload systemd config - name: Push himawaripy timer file - template: src=himawaripy.timer.j2 dest=/etc/systemd/system/himawaripy@.timer + template: src=himawaripy.timer.j2 dest=/etc/systemd/user/himawaripy.timer notify: - reload systemd config - restart himawaripy - name: Enable and start himawaripy timer - service: name="himawaripy@{{ user.name }}.timer" enabled=yes state=started + systemd: name=himawaripy.timer user=yes enabled=yes state=started + become: yes + become_user: "{{ user.name }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}" when: himawaripy.run_on == "all" - name: Remove himawaripy from trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=absent - line="himawaripy@{{ user.name }}.timer" + line="himawaripy.timer,user:{{ user.name }}" when: himawaripy.run_on == "all" - name: Disable himawaripy timer - service: name="himawaripy@{{ user.name }}.timer" enabled=no + systemd: name=himawaripy.timer user=yes enabled=no + become: yes + become_user: "{{ user.name }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}" when: himawaripy.run_on == "trusted" - name: Add himawaripy to trusted unit list lineinfile: dest=/usr/local/etc/trusted_units state=present - line="himawaripy@{{ user.name }}.timer" + line="himawaripy.timer,user:{{ user.name }}" when: himawaripy.run_on == "trusted" diff --git a/roles/himawaripy/templates/himawaripy.service.j2 b/roles/himawaripy/templates/himawaripy.service.j2 index 5b5438e..ea9316e 100644 --- a/roles/himawaripy/templates/himawaripy.service.j2 +++ b/roles/himawaripy/templates/himawaripy.service.j2 @@ -1,8 +1,7 @@ # {{ ansible_managed }} [Unit] -Description=Update desktop background with satellite imagery for user %I +Description=Update desktop background with satellite imagery [Service] Type=oneshot ExecStart=/usr/local/bin/himawaripy {{ himawaripy.flags }} -User=%i diff --git a/roles/himawaripy/templates/himawaripy.timer.j2 b/roles/himawaripy/templates/himawaripy.timer.j2 index 033a878..1bd352f 100644 --- a/roles/himawaripy/templates/himawaripy.timer.j2 +++ b/roles/himawaripy/templates/himawaripy.timer.j2 @@ -5,7 +5,7 @@ Description=Himawaripy satellite imagery timer [Timer] OnBootSec={{ himawaripy.run_boot_delay }} OnUnitActiveSec={{ himawaripy.run_time }} -Unit=himawaripy@%i.service +Unit=himawaripy.service [Install] WantedBy=timers.target