igr
igr

Reputation: 10604

Ansible not realiable with apt updates on Ubuntu

I created few Ubuntu 14.04 machines vith Vagrant. I have some ansible 2.1 playbook that uses apt in some tasks, like:

All these tasks fails randomly, on random host. For example, here is simple java8 installation role:

- name: Add Oracle Java Repository
  apt_repository:
    repo: 'ppa:webupd8team/java'
    update_cache: yes
    state: present
#  register: result
#  until: result|success
#  retries: 10
  tags: [java]

- name: Accept Java 8 License
  debconf: name='oracle-java8-installer' question='shared/accepted-oracle-license-v1-1' value='true' vtype='select'
  tags: [java]

- name: Install Oracle Java 8
  apt: name={{item}} state=latest
  with_items:
    - oracle-java8-installer
    - ca-certificates
    - oracle-java8-set-default
  tags: [java]

Pretty simple, yet apt_repository fails randomly a lot. I had to use retries hack in order to make it work. Issue is reported here, but this is just one.

The error looks like:

fatal: [xx.xx.xxx.x]: FAILED! => {"changed": false, "failed": true, "module_stderr": "",
"module_stdout": "Traceback (most recent call last):\r\n
File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1454536847.17-86172912102079/apt\", line 2630, in \r\n
 main()\r\n
File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1454536847.17-86172912102079/apt\", line 603, in main\r\n
 cache = apt.Cache()\r\n
File \"/usr/lib/python2.7/dist-packages/apt/cache.py\", line 107, in init\r\n
 self.open(progress)\r\n
File \"/usr/lib/python2.7/dist-packages/apt/cache.py\", line 151, in open\r\n
 self._cache = apt_pkg.Cache(progress)\r\n
SystemError: E:Encountered a section with no Package: header,\
 E:Problem with MergeList /var/lib/apt/lists/us-west-\
 2.ec2.archive.ubuntu.com_ubuntu_dists_trusty-updates_universe_i18n_Translation-en\
, E:The package lists or status file could not be parsed or opened.\r\n
", "msg": "MODULE FAILURE", "parsed": false}

Am I missing something? What do you do for production?

Upvotes: 4

Views: 14503

Answers (1)

300D7309EF17
300D7309EF17

Reputation: 24573

This isn't an Ansible problem, though Ansible certainly isn't helping matters.

This is a problem with apt occasionally saving a garbage file (binary of some sort) as a package list, which should be text. There's been a bug open forever about it, and here's a fix from AskUbuntu.

In this case, look at the file, confirm it is binary, then delete it:

head /var/lib/apt/lists/us-west-2.ec2.archive.ubuntu.com_ubuntu_dists_trusty-updates_universe_i18n_Translation-en
rm /var/lib/apt/lists/us-west-2.ec2.archive.ubuntu.com_ubuntu_dists_trusty-updates_universe_i18n_Translation-en

apt will recreate it when apt-get update is run.

How do you fix this with Ansible? There are some workarounds in the ansible issue you found, ultimately the apt module should be patched to simply work around this- detect the failure, remove the file, and rerun update. But sending a pull request to Ansible means it won't be released for about a year. I've found it happens rarely enough that I just manually fix it.

Upvotes: 2

Related Questions