1

I'm trying to write an ansible playbook which only upgrades the linux-generic package but cannot find the magic incantation to get it to actually work. With this play, I get the error parameters are mutually exclusive: deb|package|upgrade which google suggests is due to upgrade: full is not meant for a single package:

  - name: Check if linux-generic is installed
    command: dpkg -l linux-generic
    register: pkg_chk

  - name: update kernel if installed
    when: pkg_chk.rc == 0
    apt:
      update_cache: yes
      autoremove  : yes
      autoclean   : no
      upgrade     : full
      dpkg_options: 'force-confold,force-confdef'
      name        : linux-generic

Removing upgrade: full runs the play...

TASK [update kernel if installed] **********************************************************
ok: [vivaldi.fammed.wisc.edu]

But, when I login to the machine and run aptitude full-upgrade it shows ansible didn't do anything:

# aptitude full-upgrade
The following NEW packages will be installed:
  linux-headers-4.4.0-203{a} linux-headers-4.4.0-203-generic{a}
  linux-image-4.4.0-203-generic{a} linux-modules-4.4.0-203-generic{a}
  linux-modules-extra-4.4.0-203-generic{a}

Ok, so I thought I'd just throw the command: module at it and use bare apt commands but there is some issue with the command string that I have not escaped properly.

  - name: upgrade linux-generic
    when: pkg_chk.rc == 0
      command: apt-get install -y --only-upgrade -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold' linux-generic
      register: install_chk

  - name: autoremove linux-generic
    when: install_chk.rc == 0
      command: apt-get -y autoremove -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold'
      register: auto_chk

which yields this error:

Syntax Error while loading YAML.
  mapping values are not allowed in this context
    The error appears to be in '/usr/src/ansible/tests/upgrade-kernel-only.yml': line 24, column 12, but may
    be elsewhere in the file depending on the exact syntax problem.
    
    The offending line appears to be:
    
        when: pkg_chk.rc == 0
          command: apt-get install -y --only-upgrade -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold' linux-generic
               ^ here

I've tried escaping the : = characters, as well as replacing double-quotes and single quotes. Anyone know how to get this working?

1
  • What is this linux-generic package? I can't find any such package in Debian. That may have something to do with your problem. Feb 26, 2021 at 17:15

1 Answer 1

2

Is there any specific reason why would you not consider the ansible package module e.g.

- name: Install linux-generic
  package:
    name: linux-generic
    state: present

As far as the ansible error is concerned, you must enclose your command in double quotes since you are using single quotes inside:

 - name: upgrade linux-generic
    when: pkg_chk.rc == 0
      command: "apt-get install -y --only-upgrade -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold' linux-generic"
      register: install_chk

  - name: autoremove linux-generic
    when: install_chk.rc == 0
      command: "apt-get -y autoremove -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold'"
      register: auto_chk
3
  • I originally started with a very simple playbook like this for updating hosts but found cache was not being updated and many updates were being missed. I added update_cache but then found old kernels were not being removed so added autoremove: yes. Then found that I needed to select upgrade: dist or upgrade: full to actually get what I want. There were many corner cases like this and got me to where I am today with this stupidly complex playbook for updating all my hosts. To answer your question, yes, a simple play like what you suggest should work but in practice it does not.
    – Nstevens
    Feb 26, 2021 at 14:15
  • Understood. I have edited my initial answer to reflect your specific ansible syntax error.
    – basekat
    Feb 26, 2021 at 14:32
  • Awesome, thanks! I had to un-indent command and register (as well as the space leading your first when) but then this works great. I spent the morning upgrading all kernels so have nothing to test on now but it is running without errors so this will be a great start for next upgrade.
    – Nstevens
    Feb 26, 2021 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .