Skip to content

Suggestion to shorten Enable lingering if needed #80

@Strunck

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions