Some Ansible tricks for JDK and Docker installation.

Last week I went in trouble with setting up webex conference from Linux laptop. I resolved the issue with 32 bit Docker image started on my machine, but I realized it is not so easy to install Oracle JDK automatically. Yesterday my co-worker needed a number of machines with installed JDK and Docker. I made Ansible playbook for less than 3 minutes, but I found that Docker is not in standard RHEL 7 repo. If yo want to install Docker you need to enable “extras” repo. But Ansible subscription manager package does not support repository management. So I fallback to good-old shell module. Here are the results:

- name: install packages 
yum: name={{item}} state=present
with_items:
- unzip
- wget

- name: create install dir
file: path=/jdk state=directory
- name: download java
shell: 'wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-i586.tar.gz -O /jdk/jdk
-8u131-linux-i586.tar.gz && cd /jdk && tar -xzf jdk-8u131-linux-i586.tar.gz && for f in `ls /jdk/jdk1.8.0_131/bin`; do update-alternatives --install "/usr/bin/${f}" "${f}" "/jdk/jdk1.8.0_131/bin/${f}" 1; done'

It looks ugly but I did not have enough time to write it using get_url module, just copy-pasted shell code from Docker file. Next time I’ll use this:

- name: get JDK 
get_url:
url: http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-i586.tar.gz
headers: 'Cookie:oraclelicense=accept-securebackup-cookie'
dest: /jdk/jdk-8u131-linux-i586.tar.gz
- name: unpack JDK
unarchive: src=/jdk/jdk-8u131-linux-i586.tar.gz dest=/jdk
- name: install
shell: 'for f in `ls /jdk/jdk1.8.0_131/bin`; do update-alternatives --install "/usr/bin/${f}" "${f}" "/jdk/jdk1.8.0_131/bin/${f}" 1; done'

It will work until next JDK update, so it will be nice to use JDK fileaname and url as variables.

Next obstacle was missing repo management functionality. And next ugly solution was:

- name: Add RedHat subscription 
redhat_subscription: state=present username={{rhn_username}} password={{rhn_password}} autosubscribe=true
- name: add extras repo
shell: subscription-manager repos --enable rhel-7-server-extras-rpms

- name: install packages
yum: name={{item}} state=present
with_items:
- unzip
- wget
- docker
- git
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.