Skip to content

Instantly share code, notes, and snippets.

@Weizhang2017
Created November 17, 2019 04:07
Show Gist options
  • Save Weizhang2017/e14ca5552bc9c82a9dcea17ac4dea92b to your computer and use it in GitHub Desktop.
Save Weizhang2017/e14ca5552bc9c82a9dcea17ac4dea92b to your computer and use it in GitHub Desktop.
Install java with Ansible
- hosts: remote
handlers:
- name: update package list
apt:
update_cache: yes
tasks:
- name: download Oracle java
get_url:
url: "{{ java_donwload_url }}"
dest: /tmp
- name: create directory for java installation
file:
path: /usr/java
state: directory
mode: '0644'
- name: extract installation file
command: tar -zxvf /tmp/{{ java_package_filename }} -C /usr/java
- name: install pip
apt: name=python3-pip state=present
- name: install pexpect
pip:
name: pexpect
- name: add repository for ubuntu 18
expect:
command: add-apt-repository ppa:linuxuprising/java
responses:
'Press \[ENTER\] to continue or Ctrl\-c to cancel adding it\.': ''
when: >
ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "18"
notify: update package list
- name: add repository for ubuntu 16
command: add-apt-repository ppa:linuxuprising/java
when: >
ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "16"
notify: update package list
- name: install java 11
apt: name=oracle-java11-installer state=present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment