diff --git a/roles/mac/README.md b/roles/mac/README.md index 8eec0d5..f8e1d37 100644 --- a/roles/mac/README.md +++ b/roles/mac/README.md @@ -40,6 +40,10 @@ Manages cogitator-02, an Apple Silicon Mac on the tailnet (`mac.yml`, copied to `~/.hermes/scripts/`. Missing jobs are created; existing ones are left as they are. Today: `hermes-update-notice`, which messages you on Telegram on Mondays only when a new stable Hermes release is out. +- **Automatic login** (tag `autologin`): phil is logged in automatically after + a reboot, so everything that needs a login session (dashboard, Podman VM, + BlueBubbles, Beeper) comes back after a power cut. Uses phil's password from + the vault; redeploy after changing it. Ansible logs in as `phil`. sudo needs phil's password, which is in the vault as `vault_cogitator02.become_password`; only tasks with `become: true` use it. diff --git a/roles/mac/tasks/autologin.yml b/roles/mac/tasks/autologin.yml new file mode 100644 index 0000000..7929685 --- /dev/null +++ b/roles/mac/tasks/autologin.yml @@ -0,0 +1,21 @@ +# Log phil in automatically after a reboot (the Mac powers itself back on +# after a power cut): the dashboard, the Podman VM, BlueBubbles and Beeper +# all need a login session. FileVault is off, so this works unattended. +# It uses phil's login password from the vault; if that password changes, +# update vault_cogitator02.become_password and redeploy. +- name: Read automatic login + ansible.builtin.command: + argv: [sysadminctl, -autologin, status] + register: autologin_status + changed_when: false + check_mode: false + +- name: Turn on automatic login for {{ ansible_user }} + ansible.builtin.command: + argv: [sysadminctl, -autologin, set, -userName, "{{ ansible_user }}", + -password, "{{ vault_cogitator02.become_password }}"] + become: true + no_log: true + when: >- + (autologin_status.stdout ~ autologin_status.stderr) + is not search('Automatic login is ON.*' ~ ansible_user, ignorecase=true) diff --git a/roles/mac/tasks/main.yml b/roles/mac/tasks/main.yml index ba14aad..80ce799 100644 --- a/roles/mac/tasks/main.yml +++ b/roles/mac/tasks/main.yml @@ -45,3 +45,7 @@ - name: Podman VM ansible.builtin.import_tasks: podman.yml tags: podman + +- name: Automatic login + ansible.builtin.import_tasks: autologin.yml + tags: autologin