Ubuntu - Automate entering GRUB bootloader password after rebooting?

I have some servers that are on Ubuntu 22.04. I’m very much an amateur when it comes to Ansible.

So far (using playbooks found online), I was able to automate the updates and reboots of the servers. But each time they reboot, I need to enter the bootloader password for them to finish rebooting.

Is there any way I can also have Ansible enter the bootloader username and password? Because technically I can’t SSH into the servers as long as the password hasn’t been entered so I don’t see how Ansible would be able to either.

This is the playbook I use if needed at all:

- name: Update and, if necessary, reboot Ubuntu servers
  hosts: ubuntu
  become: true
  become_user: root

  tasks:
    - name: Ping my hosts
      ansible.builtin.ping:
      tags:
        - ping

    - name: Update apt repo and cache on all Ubuntu boxes
      ansible.builtin.apt:
        update_cache: yes 
        force_apt_get: yes
        cache_valid_time: 3600
    - name: update apt list
      ansible.builtin.apt:
        update_cache: yes
        cache_valid_time: 3600


    - name: Upgrade all packages on servers
      ansible.builtin.apt:
        upgrade: dist
        force_apt_get: yes

    - name: Check if reboot is needed on all servers
      register: reboot_required_file
      ansible.builtin.stat:
        path: /var/run/reboot-required
        get_checksum: false

    - name: Reboot (if required)
      when: reboot_required_file.stat.exists
      ansible.builtin.reboot:
        msg: "Reboot initiated by Ansible for updates"
        connect_timeout: 5
        reboot_timeout: 300
        pre_reboot_delay: 0
        post_reboot_delay: 30
        test_command: uptime

This seems like a definite no go (to me).
If they are VMs then maybe you could do something from the hypervisor level but otherwise it looks like a dead end.

1 Like

Yeah they are VMs. Probably won’t mess with the hypervisor given its managed by another team. Thanks for checking if its possible

If this is a VM on VMware platform, you can use this Ansible module to send any string or key combination (including bootloader password) to the virtual console of the VM:

https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_sendkey_module.html

But yes, for this to work, you will need access to vCenter or ESXi.

1 Like