error configuring grub-pc

I have an ansible playbook running against a Debian 10 VM. At the top of my playbook I have this environment variable:
environment:
DEBIAN-FRONTEND: noninteractive

When I try to install any package, or update all packages I get the following error:

Setting up grub-pc…
/dev/sda does not exist, so cannot grub-install to it!
You must correct your GRUB install devices before proceeding

DEBIAN_FRONTEND=dialog dpkg --configure grub-pc
dpkg --configure -a
dpkg: error processing package grub-pc
installed grub-pc package post-installation script subprocess returne error exit status 1
dpkg: depending problems prevent configuration of grub2:
grub2 depends on grub-pc (= 2.06-3-deb10u4); however:
Package grub-pc is not configured yet.

Where is /dev/sda set as the disk to run grub-pc against? (Or is that the default?) Do I have to find the real hard drive and pass it to grub-pc? I obviously don’t want a dialog to pop up as this will be running against multiple machines, some of which I can’t ssh into.

Can anyone help me figure out how to get around this?

That variable has a ‘-’ instead of an ‘_’

See dpkg_selections module to PRE populate answers/settings for
packages when there are no defaults or (like your case) the defaults
do not work.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/dpkg_selections_module.html

Brian,
Not quite sure I understand. Will holding grub-pc cause other problems in the long-term?

Not 'holding' but you pre populate the questions to avoid the
prompting. Sadly `DEBIAN-FRONTEND: noninteractive` is not enough to
avoid prompts when the package requires and answer, so the only way
around this issue is 'answering before they ask', dpkg_selections
allows you to do this.

Sorry, I meant debconf, not dpkg_selections (not sure why I keep
confusing those), here is an example of me doing the same for
installing java package.

https://github.com/bcoca/ansible-oracle_java7-role/blob/master/tasks/main.yml#L17

That make sense. I am trying to upgrade grub-pc which then prompts for the hard drive where / is mounted. When I type in debconf-show grub-pc I get a number of variables, including “install_devices”. I expect this to be something like /dev/sda or dev/nvme0n1p1, but instead it reads something similar to "/dev/disk/by-id/ata-LITEONIT_LCS256M6S…

This is what I expected to do with the debconf module:

ansible.builtin.debconf:
name: grub-pc
question: Grub Install devices
value: /dev/nvme0n1p1 (or whatever ansible facts gives me)
vtype: select

Is that correct or do I have to someone figure out the /dev/disk/by-id… variable?

that should be good, the other is probably the resolved path from a
symlink (/dev/ does this a lot)

Kathy L's profile photo

I took your suggestion to use debconf. The only issue is that in order to use debconf, I have to install debconf-utils. And when I try to install that, it tries to install grub-pc and the dialog appears.

I’m not sure where to go from here - I can’t update grub-pc or install anything without it trying to update grub-pc and bringing up a dialog box.

In the beginning of my playbook I have this:

environment:
DEBIAN_FRONTEND: noninteractive

which doesn’t seem to have any effect. (Someone suggested that it should be debian-frontend, but I did some research and it is indeed debian_frontend.)

Does anyone see how I can get around this issue?

The module requires the utils, but the debconf CLI itself does not and should already be installed.

I’m back. Now the problem I have has migrated to Debian 11. I am trying to update packages which gives me the error below. So then I try to install grub-pc by its own which does not work. Any further ideas?

Here is the code I am using and still I get the error “dpkg: dependency problems prevent configuration of grub2” and my ansible playbook dies.

  • name: Get drive
    set_fact:
    drive_name: “{{ ansible_mounts| json_query(query) }}”
    vars:
    query: “[?mount==‘/’].device”

  • name: Install debconf-utils
    apt:
    name: debconf-utils
    state: present

  • name: setup grub-pc
    shell: echo “grub-pc grub-pc/install_devices multiselect {{ drive_name }}” | debonf-set-selections

  • name: setup debconf
    shell" echo ‘debconf debconf/frontend select Noninteractive’ | debconf-set-selections"

  • name: Copy debconf selections
    debconf-set-selections | grep grub-pc > /tmp/grubpc.debconf

  • name: Load new grub-pc config
    shell: debconf-set-selections < /tmp/grubpc.debconf

  • name: Install grub
    apt:
    name: “{{ item }}”
    state: latest
    environment:
    DEBIAN_FRONTEND: noninteractive
    loop:

  • grub-pc

  • grub