Created
November 17, 2019 04:07
-
-
Save Weizhang2017/e14ca5552bc9c82a9dcea17ac4dea92b to your computer and use it in GitHub Desktop.
Install java with Ansible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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