Ansible – Troubleshooting OpenJDK-8-JDK Installation Issues on Ubuntu 18.04

ansiblejavaUbuntu

So I am trying to setup an Ubuntu host using ansible and one of my requirements is to use java8

After researching a lot of discovering the various deprecation posts about the oracle PPA etc, I settled on installing openjdk-8-jdk

So here's my scenario – I launched a fresh ubuntu image from AWS and the first thing I did

apt-get update
apt-get install openjdk-8-jdk

Perfect – that worked, so now to put this into my ansible playbook, looks something like this:

- name: Update all Ubuntu packages
  apt:
    upgrade: "dist"
  when: ansible_distribution == 'Ubuntu'

- name: Install required Ubuntu packages
  apt:
    name: "{{ packages }}"
    state: present
  vars:
    packages:
      - openjdk-8-jdk

But when ansible runs, it errors out with:

amazon-ebs: TASK [system : Install required Ubuntu packages] *******************************
amazon-ebs: fatal: [default]: FAILED! => {"changed": false, "msg": "No package matching 'openjdk-8-jdk' is available"}
amazon-ebs:     to retry, use: --limit @/Users/cparker/Git/tungsten-products/ami/replicator/ansible/playbook-ubuntu.retry

Also, yes, the fresh image I launched to test is exactly the same AMI image ID/Build that ansible is also launching

I'm lost 🙁

I've fund quite a few results searching but they all reference the now obsolete methods for using the Oracle builds etc, but I cant find anything specific to this issue

Image is Ubuntu 18.04, to be specific ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-20190814

Ansible is 2.7.10

Best Answer

By default in cloud images there is no package list locally cached.

Set

update_cache: yes

to have apt update it's cache before you install a package.

Related Topic