Wednesday, September 14, 2016

Using ansible to install Oracle Java on an ec2 box running in the cloud

I am writing this down so I don't forget. I started this task but had to stop a few times, and then remember where I left off and at some point, others will need to know how to get started.

Install ansible

brew install ansible

Install Amazon EC2 Ansible integration tool

Go here and follow instructions for Amazon EC2 Ansible integration tool. You will run a Python script and setup a few environment variable. It is painless. This will create an ansible inventory file based on your EC2 environment.

Start ssh agent with your key

$ ssh-agent bash 
$ ssh-add ~/.ssh/YOUR_KEY.pem 

Install ansible Oracle Java install plugin

$ ansible-galaxy install ansiblebit.oracle-java

Start up an EC2 box tag it as elk=elk

However you like, start up an EC2 instance and tag it with the tag elk=elk. This is just the type of box. In this case, I am in the process of writing an ansible setup script for an ELK stack.

Test your ansible connection with the ping module

$ ansible tag_elk_elk -m ping -u ec2-user | SUCCESS => {
    "changed": false, 
    "ping": "pong"

Create an ansible playbook

- hosts: tag_elk_elk
  user: ec2-user
  sudo: yes
     - { role: ansiblebit.oracle-java,
         oracle_java_set_as_default: yes,
         oracle_java_version: 8,
         oracle_java_version_update: 102,
         oracle_java_version_build: 14}

  - name: ensure apache is at the latest version
    yum: name=httpd state=latest

Run the ansible playbook

$ ansible-playbook elk_install_playbook.yml 
Ok. Now back to creating my ansible ELK install script. There are also tasks for creating an Amazon box with Ansible.
Kafka and Cassandra support, training for AWS EC2 Cassandra 3.0 Training