Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion to shorten Enable lingering if needed #80

Open
Strunck opened this issue Jun 14, 2023 · 2 comments
Open

Suggestion to shorten Enable lingering if needed #80

Strunck opened this issue Jun 14, 2023 · 2 comments

Comments

@Strunck
Copy link

Strunck commented Jun 14, 2023

    - 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
Copy link
Owner

ikke-t commented Jun 14, 2023

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

@Strunck
Copy link
Author

Strunck commented Jun 15, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants