ikke-t / podman-container-systemd

creates systemd files and creates containers using podman
118 stars 44 forks source link

Suggestion to shorten Enable lingering if needed #80

Open Strunck opened 1 year ago

Strunck commented 1 year ago
    - name: Check if user is lingering
      ansible.builtin.stat:
        path: "/var/lib/systemd/linger/{{ container_run_as_user }}"
      register: user_lingering
      when: container_run_as_user != "root"

    - name: Enable lingering is needed
      ansible.builtin.command: "loginctl enable-linger {{ container_run_as_user }}"
      when:
        - container_run_as_user != "root"
        - not user_lingering.stat.exists

The above could probably be shortend to the following:

    - name: Enable lingering if needed
      ansible.builtin.command: 
        cmd: "loginctl enable-linger {{ container_run_as_user }}"
        creates: "/var/lib/systemd/linger/{{ container_run_as_user }}"
      when:
        - container_run_as_user != "root"    

The "creates" directive should ensure idempotency.

ikke-t commented 1 year ago

Good idea! Would you be interested to write your name to history in form of PR? 😁

Strunck commented 1 year ago

Thank for the encouragement. I have never done a PR before. If I find the time, I will try...