apt-get autoremove - how to use it and how to check that it is doing what it should ?

800 views
Skip to first unread message

Wayne Pascoe

unread,
Jan 4, 2016, 10:11:36 AM1/4/16
to Ansible Project
Hi all,

I'm trying to create some simple playbooks to manage a few hosts. One of the tasks I'm trying to complete is to autoremove unneeded packages. I'm using Ansible 2.1.0 on Ubuntu 14.04 (control machine and managed hosts).

I started with the following playbook:
---
- hosts: vpn_endpoint
  tasks
:
     
- name: update apt packages
        apt
: upgrade=dist update_cache=yes
        become
: yes
     
- name: autoremove unneeded packages
        command
: apt-get -y autoremove
        become
: yes

This worked, but provided the following warning:

TASK [autoremove unneeded packages] ********************************************
changed: [host]
 [WARNING]: Consider using apt-get module rather than running apt-get

Some searching showed me some projects that use a variable 'apt_autoremove: yes' (e.g. https://github.com/weareinteractive/ansible-apt/blob/master/README.md) but I do not see any mention of this in the source at https://github.com/ansible/ansible-modules-core/blob/stable-2.0/packaging/os/apt.py

I tried modifying my playbook to be the following:
---
- hosts: all
  vars
:
      apt_cache_valid_time
: 3600
      apt_autoremove
: yes
      apt_autoclean
: yes
  tasks
:
     
- name: update apt packages
        apt
: upgrade=dist update_cache=yes
        become
: yes


After doing that, I no longer see the warning, but the autoremove step on the host is not being done (see the following output for apt-get dist-upgrade).

Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  linux-headers-3.13.0-32 linux-headers-3.13.0-32-generic
  linux-headers-3.13.0-51 linux-headers-3.13.0-51-generic
  linux-image-3.13.0-32-generic linux-image-3.13.0-51-generic
  linux-image-extra-3.13.0-32-generic linux-image-extra-3.13.0-51-generic
Use 'apt-get autoremove' to remove them.

So that brings me to my question - what's the right way to do an auto remove step with apt and Ansible ? Should I stick to the command module and ignore the warning ? If so, is there any way to supress the warning just for this specific task ?

Thanks in advance,




Pär Berge

unread,
Jan 5, 2016, 3:36:12 AM1/5/16
to Ansible Project
Hi,

I would use command (or shell) until it's implemented in apt module.
Here is the feature request issue ticket:

Mischa ter Smitten

unread,
Jan 5, 2016, 2:16:26 PM1/5/16
to Ansible Project
It's implemented in this role.

Op maandag 4 januari 2016 16:11:36 UTC+1 schreef Wayne Pascoe:

Wayne Pascoe

unread,
Jan 5, 2016, 2:30:22 PM1/5/16
to Ansible Project
Thanks,

Is there any way to supress the error on this particular play until then ?

Wayne Pascoe

unread,
Jan 5, 2016, 2:30:59 PM1/5/16
to Ansible Project
Thanks - I'm trying to avoid pulling in an entire role if I can help it, so the shell play looks simpler for now.
Reply all
Reply to author
Forward
0 new messages