generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure user linger is enabled and disabled correctly
Cause: The role was not always enabling user lingering before creating resources, and not always canceling lingering after removing resources. Consequence: The role would give errors if attempting to create a secret or other resource requiring lingering, or would leave lingering enabled after removing resources. Fix: Centralize linger handling and keep track of users which may need linger canceling. Ensure linger is canceled for all users if all of that user's resources are removed and linger is no longer needed. Result: Resources for rootless users are always created properly. Lingering is always canceled when no longer needed. Fix issue with toml.j2 - ensure non-string values are written as non-strings. Fix idempotency issue where you could not clean up twice. Allow testing rootless quadlet on EL8 by configuring settings and kernel parameters and rebooting. Fix several cleanup issues, and dump journal if there are test errors. Construct the __params dict to pass to `podman_secret` to fix the JSON string issue with `data` on both Ansible 2.9 and later. Signed-off-by: Rich Megginson <[email protected]>
- Loading branch information
Showing
15 changed files
with
626 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
# Input: | ||
# * __podman_linger_user - username | ||
- name: Get user information | ||
getent: | ||
database: passwd | ||
key: "{{ __podman_linger_user }}" | ||
fail_key: true | ||
when: "'getent_passwd' not in ansible_facts or | ||
__podman_linger_user not in ansible_facts['getent_passwd']" | ||
|
||
- name: Set cancel linger vars | ||
set_fact: | ||
__podman_xdg_runtime_dir: >- | ||
/run/user/{{ ansible_facts["getent_passwd"][__podman_linger_user][1] }} | ||
- name: Stat XDG_RUNTIME_DIR | ||
stat: | ||
path: "{{ __podman_xdg_runtime_dir }}" | ||
register: __podman_xdg_stat | ||
|
||
- name: Gather facts for containers | ||
containers.podman.podman_container_info: | ||
environment: | ||
XDG_RUNTIME_DIR: "{{ __podman_xdg_runtime_dir }}" | ||
become: true | ||
become_user: "{{ __podman_linger_user }}" | ||
when: __podman_xdg_stat.stat.exists | ||
register: __podman_container_info | ||
|
||
- name: Gather facts for networks | ||
command: podman network ls -q | ||
register: __podman_networks | ||
changed_when: false | ||
environment: | ||
XDG_RUNTIME_DIR: "{{ __podman_xdg_runtime_dir }}" | ||
become: true | ||
become_user: "{{ __podman_linger_user }}" | ||
when: __podman_xdg_stat.stat.exists | ||
|
||
- name: Gather secrets | ||
command: podman secret ls -n -q | ||
register: __podman_linger_secrets | ||
changed_when: false | ||
environment: | ||
XDG_RUNTIME_DIR: "{{ __podman_xdg_runtime_dir }}" | ||
become: true | ||
become_user: "{{ __podman_linger_user }}" | ||
when: __podman_xdg_stat.stat.exists | ||
|
||
- name: Cancel linger if no more resources are in use | ||
command: loginctl disable-linger {{ __podman_linger_user }} | ||
when: | ||
- __podman_xdg_stat.stat.exists | ||
- __podman_container_info.containers | length == 0 | ||
- __podman_networks.stdout_lines | reject("match", "^podman$") | | ||
reject("match", "^podman-default-kube-network$") | | ||
list | length == 0 | ||
- __podman_linger_secrets.stdout == "" | ||
changed_when: true | ||
args: | ||
removes: /var/lib/systemd/linger/{{ __podman_user }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
# Input: | ||
# * __podman_rootless - true or false | ||
# * __podman_user - name of user | ||
# * __podman_item_state - present or absent | ||
# Globals: __podman_cancel_user_linger | ||
- name: Enable linger if needed | ||
when: | ||
- __podman_rootless | bool | ||
- __podman_item_state | d('present') != 'absent' | ||
block: | ||
- name: Enable linger if needed | ||
command: loginctl enable-linger {{ __podman_user }} | ||
when: __podman_rootless | bool | ||
args: | ||
creates: /var/lib/systemd/linger/{{ __podman_user }} | ||
|
||
- name: Mark user as not yet needing to cancel linger | ||
set_fact: | ||
__podman_cancel_user_linger: "{{ __podman_cancel_user_linger | | ||
difference([__podman_user]) }}" | ||
|
||
- name: Mark user for possible linger cancel | ||
set_fact: | ||
__podman_cancel_user_linger: "{{ __podman_cancel_user_linger | | ||
union([__podman_user]) }}" | ||
when: | ||
- __podman_rootless | bool | ||
- __podman_item_state | d('present') == 'absent' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.