Pages

Ansible - Error - stderr: E: There are problems and -y was used without --force-yes

In case your tasks is to install some packages and it errors out as below

  

- name: Install linux-headers
  apt: pkg={{item}} 
       state=installed 
       install_recommends=yes 
       update_cache=yes
  with_items: 
      - linux-headers-generic
      - dkms
  sudo: yes




failed: [parallelsUbuntu] => (item=linux-headers-generic,dkms) => {"failed": true, "item": "linux-headers-generic,dkms"}
stderr: E: There are problems and -y was used without --force-yes

stdout: Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  cpp fakeroot gcc libfakeroot linux-headers-3.13.0-63
  linux-headers-3.13.0-63-generic patch
Suggested packages:
  cpp-doc dpkg-dev debhelper gcc-multilib manpages-dev autoconf automake1.9
  libtool flex bison gdb gcc-doc diffutils-doc
The following NEW packages will be installed:
  cpp dkms fakeroot gcc libfakeroot linux-headers-3.13.0-63
  linux-headers-3.13.0-63-generic linux-headers-generic patch
0 upgraded, 9 newly installed, 0 to remove and 17 not upgraded.
Need to get 0 B/9846 kB of archives.
After this operation, 78.0 MB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  cpp gcc patch dkms libfakeroot fakeroot linux-headers-3.13.0-63
  linux-headers-3.13.0-63-generic linux-headers-generic

msg: '/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold"   install 'linux-headers-generic' 'dkms'' failed: E: There are problems and -y was used without --force-yes


FATAL: all hosts have already failed -- aborting

Solution

The solution is to just add the option of force=yes

  
apt: pkg={{item}} 
       state=installed 
       install_recommends=yes 
       update_cache=yes
       force=yes


which is equivalent to what we would have done manually on the terminal

  
sudo apt-get install some-deb -y --force-yes


Every time I use Ansible my admiration for it only increases, how well advanced concepts have been implemented in such simple ways!