podman-container-systemd icon indicating copy to clipboard operation
podman-container-systemd copied to clipboard

Suggestion to shorten Enable lingering if needed

Open Strunck opened this issue 2 years ago • 2 comments

    - 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.

Strunck avatar Jun 14 '23 06:06 Strunck

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

ikke-t avatar Jun 14 '23 14:06 ikke-t

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

Strunck avatar Jun 15 '23 06:06 Strunck