I have a raspberry pi with "Raspbian GNU/Linux 11 (bullseye)" which I set up via ansible scripts. Now, I want to enable the "console auto-login". I know I can do that with the raspi-config tool. However, I want to enable the auto login via ansible as well. Is there a way to enable the console auto-login without user interaction via commandline?
1 Answer
As mentioned by @SteveRobillard, raspi-config can be used in noninteractive mode. The functionality is, however, not documented. The functions have to be checked in the source code https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config.
To enable console auto-login, one can use:
sudo raspi-config nonint do_boot_behaviour B2
To check the auto-login, use:
sudo raspi-config nonint get_autologin
This should print 0 if autologin is enabled.
So to enable console autologin via ansible, the following task can be used:
- name: enable console auto login
become: true
ansible.builtin.command: raspi-config nonint do_boot_behaviour B2
-
What this command does is create the file /etc/systemd/system/[email protected]/autologin.conf. The reverse command raspi-config nonint do_boot_behaviour B1 deletes it– GrumollJun 1, 2023 at 14:55