- name: Ensure marker directory exists ansible.builtin.file: path: /run/tuxflotte/agent/applied state: directory mode: "0755" # PAM-Dateilayout unterscheidet sich zwischen RedHat- (GDM/authselect) und # Debian-Familie (LightDM/common-*) - beide Backends (fedora, mint) nutzen # denselben Rollennamen "guest-session" (siehe blueprints-Seed), die Rolle # muss also auf beiden funktionieren. - name: Determine PAM file locations for this distribution family ansible.builtin.set_fact: tuxflotte_guest_pam_auth_file: "{{ '/etc/pam.d/gdm-password' if ansible_facts['os_family'] == 'RedHat' else '/etc/pam.d/lightdm' }}" tuxflotte_guest_pam_session_file: "{{ '/etc/pam.d/postlogin' if ansible_facts['os_family'] == 'RedHat' else '/etc/pam.d/common-session' }}" - name: Ensure nopasswdlogin group exists (present) ansible.builtin.group: name: nopasswdlogin state: present when: tuxflotte_state == "present" - name: Ensure gast user exists (present) ansible.builtin.user: name: gast comment: "Tuxflotte Gastsitzung" groups: nopasswdlogin append: true shell: /bin/bash password_lock: true when: tuxflotte_state == "present" # Debian/LightDM bringt eine Zeile mit identischer Wirkung bereits # standardmäßig mit, allerdings mit anderer Formatierung - regexp erkennt # sie als bereits erfüllt (kein Duplikat). Auf Fedora/GDM existiert noch # nichts Passendes, die Zeile wird frisch eingefügt. - name: Allow passwordless login for nopasswdlogin group ansible.builtin.lineinfile: path: "{{ tuxflotte_guest_pam_auth_file }}" regexp: '^auth\s+sufficient\s+pam_succeed_if\.so\s+user\s+ingroup\s+nopasswdlogin\s*$' line: "auth sufficient pam_succeed_if.so user ingroup nopasswdlogin" insertbefore: BOF state: present when: tuxflotte_state == "present" - name: Ensure ephemeral tmpfs home for gast (pam_namespace polyinstantiation) ansible.builtin.lineinfile: path: /etc/security/namespace.conf line: "/home/gast tmpfs tmpfs:mntopts=size=2G,mode=0700 root,gast" regexp: '^/home/gast\s' state: present when: tuxflotte_state == "present" - name: Enable pam_namespace for login sessions ansible.builtin.lineinfile: path: "{{ tuxflotte_guest_pam_session_file }}" line: "session required pam_namespace.so" state: present when: tuxflotte_state == "present" - name: Record that the guest-session role ran ansible.builtin.copy: dest: /run/tuxflotte/agent/applied/guest-session.marker content: "{{ ansible_date_time.iso8601 }}\n" mode: "0644" when: tuxflotte_state == "present" - name: Remove ephemeral tmpfs home entry for gast (Auftrag abgewählt) ansible.builtin.lineinfile: path: /etc/security/namespace.conf regexp: '^/home/gast\s' state: absent when: tuxflotte_state == "absent" # Entfernt die nopasswdlogin-Regel vollständig, nicht nur den gast-Account - # betrifft auf Debian/LightDM auch den distributionseigenen Default-Eintrag. # Bewusst in Kauf genommen: diese Rolle ist der einzige Verwalter der # nopasswdlogin-Konvention in diesem Katalog, Wiederherstellung beim # nächsten present-Lauf ist kostenlos. - name: Remove passwordless login rule for nopasswdlogin group (Auftrag abgewählt) ansible.builtin.lineinfile: path: "{{ tuxflotte_guest_pam_auth_file }}" line: "auth sufficient pam_succeed_if.so user ingroup nopasswdlogin" state: absent when: tuxflotte_state == "absent" - name: Remove gast user and home (Auftrag abgewählt) ansible.builtin.user: name: gast state: absent remove: true when: tuxflotte_state == "absent" - name: Remove guest-session marker (Auftrag abgewählt) ansible.builtin.file: path: /run/tuxflotte/agent/applied/guest-session.marker state: absent when: tuxflotte_state == "absent"