Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apt module failing to update cache in Ubuntu 16.04 LTS #18987

Closed
YPCrumble opened this issue Dec 8, 2016 · 36 comments · Fixed by #27962
Closed

Apt module failing to update cache in Ubuntu 16.04 LTS #18987

YPCrumble opened this issue Dec 8, 2016 · 36 comments · Fixed by #27962
Labels
affects_2.0 This issue/PR affects Ansible v2.0 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@YPCrumble
Copy link

From @tjbenator on April 23, 2016 7:18

ISSUE TYPE
  • Bug Report
COMPONENT NAME
  • apt
ANSIBLE VERSION
ansible 2.0.1.0
CONFIGURATION

Mostly defaults, nothing that would affect this.
https://github.com/binarypenguin/automation/blob/master/ansible.cfg

OS / ENVIRONMENT

Ubuntu 16.04 -> Ubuntu 16.04

SUMMARY
STEPS TO REPRODUCE
ansible [HOSTNAME] -m apt -a 'update_cache=yes cache_valid_time=3600'
EXPECTED RESULTS

Download apt updates

ACTUAL RESULTS
HOSTNAME | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "cache_valid_time": 3600, 
            "deb": null, 
            "default_release": null, 
            "dpkg_options": "force-confdef,force-confold", 
            "force": false, 
            "install_recommends": null, 
            "package": null, 
            "purge": false, 
            "state": "present", 
            "update_cache": true, 
            "upgrade": null
        }, 
        "module_name": "apt"
    }, 
    "msg": "Could not fetch updated apt files"
}

sudo apt-get update works fine on the host. I thought the issue was that Ubuntu 16.04 LTS does not include Aptitude by default. Also python-apt wasn't installed. Installing them both on the remote machine did not fix the issue.

Copied from original issue: ansible/ansible-modules-core#3523

@YPCrumble
Copy link
Author

From @koenpunt on May 29, 2016 16:2

For me installing the python-minimal and aptitude packages was enough, but it would be nice if Ansible just used the apt command.

@YPCrumble
Copy link
Author

From @ansibot on July 31, 2016 22:16

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@YPCrumble
Copy link
Author

From @subcreator on September 2, 2016 10:20

I have the same problem!

@YPCrumble
Copy link
Author

From @ansibot on September 2, 2016 10:28

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@YPCrumble
Copy link
Author

From @resuni on September 16, 2016 3:40

Experiencing the same problem on Debian 8 with Ansible 2.1.1.0.

For me installing the python-minimal and aptitude packages was enough, but it would be nice if Ansible just used the apt command.

Should probably use apt-get instead. apt will throw a warning, even if just passing it through grep or sed:

$ apt search test | grep hello

WARNING: apt does not have a stable CLI interface yet. Use with caution in scripts.

@YPCrumble
Copy link
Author

From @zezke on September 20, 2016 13:0

I can verify that install aptitude did work, but it brought along some extra packages as well. Would be nice if all that could be avoided by making Ansible use apt-get instead.

@YPCrumble
Copy link
Author

From @ansibot on September 20, 2016 13:17

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@YPCrumble
Copy link
Author

From @ansibot on October 6, 2016 14:44

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@YPCrumble
Copy link
Author

From @codegastudio on October 19, 2016 13:34

Same problem with raspberry pi on jessie
update_cache option looks to be the problem

ansible 2.1.2.0

@YPCrumble
Copy link
Author

From @Pkuutn on October 20, 2016 13:49

I have the same issue with Debian Stretch
Ansible 2.1.1

@YPCrumble
Copy link
Author

From @ansibot on October 22, 2016 8:56

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@YPCrumble
Copy link
Author

From @gerhard-tinned on October 23, 2016 18:49

+1

I have the same issue. Interestingly, my Ubuntu servers work without problem. my Debian host on the other hand shows exactly this issue.

@YPCrumble
Copy link
Author

From @ansibot on November 6, 2016 9:51

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@YPCrumble
Copy link
Author

From @bdgscotland on November 22, 2016 9:28

+1 on AWS Ubuntu 16.04 LTS AMI and Ansible 2.2.0.0
Workaround for me:
pre_tasks:

  • name: 'install python2'
    raw: sudo apt-get -y install python-simplejson

  • name: 'install aptitude'
    raw: sudo apt-get -y install aptitude

@YPCrumble
Copy link
Author

From @ansibot on November 22, 2016 9:59

@ansible, ping. This issue is still waiting on your response.
click here for bot help

@YPCrumble
Copy link
Author

From @bekerov on December 4, 2016 18:1

same trouble. i cant figure out. Installed today ansible on new machine and my ansible is not work

@YPCrumble
Copy link
Author

From @ansibot on December 7, 2016 20:4

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

@Pkuutn
Copy link

Pkuutn commented Dec 8, 2016 via email

@ansibot ansibot added module This issue/PR relates to a module. plugin affects_2.0 This issue/PR affects Ansible v2.0 labels Dec 13, 2016
@dev169
Copy link

dev169 commented Dec 13, 2016

I am having this exact issue, with Ubuntu 16.04 and ansible 2.2.0.0.

@ttalla14
Copy link

I had same issue using APT | Update on Debian 7.
So when figuring out, it showed me that there are /etc/sources.list.d/*.list configs are changed and the apt-update can't locate those deb mirrors.
When I moved or removed from the location and hitting again the play, it worked fine with my case.
Hope it helps. And Thanks man for pointing out at .list configs @Pkuutn.

mm0 added a commit to mm0/ansible-role-baseline that referenced this issue Dec 20, 2016
@koenpunt
Copy link
Contributor

The weirdest thing about this actually is that the following fails:

- apt: update_cache=yes upgrade=safe cache_valid_time=3600

But this does work:

- apt: name=aptitude state=present
- apt: update_cache=yes upgrade=safe cache_valid_time=3600

@gsong
Copy link

gsong commented Dec 23, 2016

@koenpunt That makes perfect sense, no? Since the issue is that a safe-upgrade depends on aptitude which is installed by your first task. This is the current work-around.

@koenpunt
Copy link
Contributor

koenpunt commented Dec 23, 2016

I would think that the apt task always uses the same tool in the background, but apparently it's not.

@jimi-c jimi-c removed the plugin label Jan 4, 2017
@nhodges
Copy link

nhodges commented Jan 27, 2017

I am also experiencing the "Could not fetch updated apt files" error when update_cache=yes is set.

@elaijuh
Copy link

elaijuh commented Feb 5, 2017

same here with ubuntu 16.04 lts and ansible 2.2.1.0

@pierreant-p
Copy link

Same issue on ansible 2.2.1.0

@yuriybabenko
Copy link

Same issue here. @koenpunt's workaround seems to have helped!

@jamesongithub
Copy link

@YPCrumble did you ever find a workaround? aptitude didn't help for me also. running everything as raw didn't either

@misham
Copy link

misham commented May 4, 2017

Are there plans to address this issue? The current workaround, for me, is to run the following command before using Ansible:

sudo apt-get install -y aptitude software-properties-common

I use Packer with Ansible, so it's fairly straight forward to put that into a script that bootstraps Ansible on Ubuntu but it's a really ugly hack.

@3issamben
Copy link

I'm having this exact issue, with Ubuntu 16.04 and ansible 2.2.0.0.
When I run apt commands on my host machine I get no error

@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@MarcinOrlowski
Copy link

MarcinOrlowski commented Jul 15, 2017

@misham luckily you can work this around within Ansible, as only certain apt features require aptitude (namely upgrade) to work. So instead of

- name: "Upgrade existing packages"
  apt: 
    update_cache: yes 
    upgrade: yes 

which would fail due to lack of aptitude, you change your playbook to satisfy Ansible needs first, then you do your remaining tasks:

- name: "Working around Ansible lameness..."
  apt:
    pkg: "{{ item }}"
    state: latest
    update_cache: yes
    cache_valid_time: 3600
  with_items:
    - aptitude

- name: "Upgrade existing packages"
  apt: 
    update_cache: yes 
    upgrade: yes 

and you are good as before.

@ansibot
Copy link
Contributor

ansibot commented Jul 15, 2017

@TomTucka
Copy link

Also getting this on version 2.3.1.0....

Tried using @MarcinOrlowski solution but that hasn't worked for me and produces a huge error message

https://pastebin.com/Q9JHXX0y <-- Yeah It's that big!!

@valentin-krasontovitsch
Copy link
Contributor

The behavior of aptitude safe-upgrade (according to its man page) is

  • update existing packages
  • install new packages where necessary for upgrading existing packages
  • remove packages which are unused

and the second point seems to be the reason for using aptitude, cf. #2540

With apt-get, it seems like we would have to run

apt-get upgrade --with-new-pkgs --autoremove

where the options induce the expected & desired behavior. This is again according to the man page, and also this askubuntu question)

So... I'm gonna submit a pull request where the upgrade: yes/safe induce the above apt-get command. Also, upgrade: full will become synonymous with upgrade: dist and both will trigger apt-get dist-upgrade.

An argument in favor of apt-get over aptitude is that the former is more back-end, while the latter is more user-friendly - I suppose (peronsal humble opinion) that in ansible core, we should try to use the potentially more stable and backwards compatible back-end tools.

@valentin-krasontovitsch
Copy link
Contributor

@gurutom I only took a very quick look at your pasetbin, but the fact that the output contains

No apport report written because the error message indicates its a followup error from a previous failure

is (at least for me) an indicator that this might be due to a pre-existing condition ; )

Looking a bit further, I see

stdout: No space left on device

Wild guess: Is it possible that your boot partition is full of kernel images?
The guess is based on these lines:

mkinitramfs failure cpio 141 gzip 1\r\n
update-initramfs: failed for /boot/initrd.img-4.4.0-87-generic with 1.\r\n
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1\r\n
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-4.4.0-87-generic.postinst line 1052.\r\n
dpkg: error processing package linux-image-4.4.0-87-generic (--configure):\r\n
subprocess installed post-installation script returned error exit status 2\r\n
dpkg: dependency problems prevent configuration of linux-image-extra-4.4.0-87-generic:\r\n
linux-image-extra-4.4.0-87-generic depends on linux-image-4.4.0-87-generic; however:\r\n 
Package linux-image-4.4.0-87-generic is not configured yet.

I think there might be something wrong with your system, @MarcinOrlowski's solution should fix it.

valentin-krasontovitsch pushed a commit to valentin-krasontovitsch/ansible that referenced this issue Jul 27, 2017
In answer to ansible#2540, `aptitude` was introduced as tool of choice for running
upgrades in the apt module and installing new packages that arise as
dependencies during upgrades.

This recently lead to problems, as for example Ubuntu Xenial (16.04) ships
without aptitude (installed).

Studying the man pages of both apt-get and aptitude, it appears that we can
achieve the effects of `aptitude safe-upgrade` using

```
apt-get upgrade --with-new-pkgs --autoremove
```

while `aptitude full-upgrade` seems to be identical to `apt-get dist-upgrade`.

An argument in favor of apt-get over aptitude is that the former is more
back-end, while the latter is more user-friendly - I suppose (peronsal humble
opinion) that in ansible core, we should try to use the potentially more stable
and backwards compatible back-end tools.

Cf. ansible#18987
valentin-krasontovitsch pushed a commit to valentin-krasontovitsch/ansible that referenced this issue Aug 9, 2017
In answer to ansible#2540, `aptitude` was introduced as tool of choice for running
upgrades in the apt module and installing new packages that arise as
dependencies during upgrades.

This recently lead to problems, as for example Ubuntu Xenial (16.04) ships
without aptitude (installed).

Studying the man pages of both apt-get and aptitude, it appears that we can
achieve the effects of `aptitude safe-upgrade` using

```
apt-get upgrade --with-new-pkgs --autoremove
```

while `aptitude full-upgrade` seems to be identical to `apt-get dist-upgrade`.

We use `apt-get` as described above as a fall-back in case that `aptitude`
cannot be found, issuing a warning when it does so.

Furthermore it introduces a flag `force_apt_get` which may be used to enforce
usage of apt-get (which does not issue a warning).

The integration tests are updated accordingly.

Cf. also the discussion in ansible#27370.

Fixes ansible#18987
bcoca pushed a commit that referenced this issue Aug 10, 2017
In answer to #2540, `aptitude` was introduced as tool of choice for running
upgrades in the apt module and installing new packages that arise as
dependencies during upgrades.

This recently lead to problems, as for example Ubuntu Xenial (16.04) ships
without aptitude (installed).

Studying the man pages of both apt-get and aptitude, it appears that we can
achieve the effects of `aptitude safe-upgrade` using

```
apt-get upgrade --with-new-pkgs --autoremove
```

while `aptitude full-upgrade` seems to be identical to `apt-get dist-upgrade`.

We use `apt-get` as described above as a fall-back in case that `aptitude`
cannot be found, issuing a warning when it does so.

Furthermore it introduces a flag `force_apt_get` which may be used to enforce
usage of apt-get (which does not issue a warning).

The integration tests are updated accordingly.

Cf. also the discussion in #27370.

Fixes #18987
hiraethmarkb pushed a commit to hiraethmarkb/local_setup that referenced this issue Feb 18, 2018
see:
* ansible/ansible-modules-core#3523
* ansible/ansible#18987

modified:   roles/common/tasks/includes/development/development-python3.yml
modified:   roles/common/tasks/includes/development/development-zeal.yml
modified:   roles/common/tasks/includes/utilities/utilities-antivirus.yml
modified:   roles/common/tasks/includes/utilities/utilities-cli.yml
modified:   roles/common/tasks/includes/utilities/utilities-gui.yml
modified:   roles/common/tasks/includes/utilities/utilities-passwords.yml
modified:   roles/common/tasks/includes/utilities/utilities-powerline.yml
modified:   roles/common/tasks/includes/utilities/utilities-syncthing.yml
modified:   roles/common/tasks/includes/utilities/utilities-vim.yml
modified:   roles/common/tasks/main.yml
@ralffunk
Copy link

Even though this is closed, I would like to add my experience in case it helps others.

In my case ansibles "apt: update_cache: yes" was failing because the command "sudo apt update" was raising some warnings about a cdrom source that it could not find or wasn't in the expected format. Apparently the ansible "apt" module caught these warnings as errors and proceded to fail the task.

My solution was to remove (or comment) the lines with "cdrom" in "/etc/apt/sources.list". I did this through ansible, using the "lineinfile" module.

My setup:

  • local machine: ubuntu 17.10
  • target host: ubuntu server LTS 16.04.2
  • Ansible 2.4
  • Python 3 on both machines

Hope this helps someone.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.0 This issue/PR affects Ansible v2.0 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet