Install Java with Ansible

Sample to install Java with Ansible


#Temporary directory
temp_dir: /var/tmp

#Java distribution

#Java installation directory
java_install_dir: /usr/lib/jvm

# Java Home
java_home: "{{ java_install_dir }}/jdk-{{ java_version }}"


- import_tasks: setup.yml


- name: Find installed Java.
    paths: "{{ java_install_dir }}"
    file_type: directory
    patterns: "jdk-{{ java_version }}*"
  register: installed_java

- name: Delete installed Java.
    path: "{{ item.path }}"
    state: absent
    - "{{ installed_java.files }}"

- name: Download Java distribution file.
    url: "{{ java_distributions[ java_version ].url }}"
    dest: "{{ temp_dir }}"
  register: distribution_file

- name: Unarchive Java distribution file.
    src: "{{ distribution_file.dest }}"
    dest: "{{ java_install_dir }}"
    remote_src: yes
    list_files: yes
    owner: root
    group: root
    mode: u=rwX,go=rX
  register: contents

- name: Create symbolic link.
    src: "{{ java_install_dir }}/{{ contents.files[ 0 ] | regex_replace( '.*/(.+)/$', '\\1' ) }}"
    dest: "{{ java_home }}"
    state: link

- name: Make alternatives.
    name: "{{ item }}"
    link: "/usr/bin/{{ item }}"
    path: "{{ java_home }}/bin/{{ item }}"
    - java
    - javac

- name: Delete Java distribution file.
    path: "{{ distribution_file.dest }}"
    state: absent

Recommended Posts

Install Java with Ansible
Install Java and Tomcat with Ansible
Install java with Homebrew
Download Java with Ansible
Install Java 7 with Homebrew (cask)
Install Oracle JDK 8 with Ansible
Install java with Ubuntu 16.04 based Docker
Install Java with zip on Windows
Install Java8 with Yum on Amazon Linux
Install Ruby 3.0.0 with asdf
Install Java on Mac
Change seats with java
[Java] Install Amazon Corretto 8
Install OpenJDK8 with RPM
Install Java 11 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Comfortable download with JAVA
Install Java 14 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Install Gradle with ubuntu16.04
Switch java with direnv
Install Java 8 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Let's scrape with Java! !!
Build Java with Wercker
Switch versions with alternatives after yum install java
Install Composer with Docker
Endian conversion with JAVA
Install Java 8 (OpenJDK: Amazon Corretto) on macOS with Homebrew
Install Java 8 (OpenJDK: Zulu Community) on macOS with Homebrew
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Java multi-project creation with Gradle
Getting Started with Java Collection
Clogged with Express npm install
Network install CentOS 8 with Kickstart.
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
Rewrite Java try-catch with Optional
Java to play with Function
Try DB connection with Java
Enable Java EE with NetBeans 9
[Java] JavaConfig with Static InnerClass
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Version control Java with SDKMAN
RSA encryption / decryption with java 8
Paging PDF with Java + PDFBox.jar
Sort strings functionally with java
Object-oriented (java) with Strike Gundam
Install Java on WSL Ubuntu 18.04
[Java] Content acquisition with HttpCliient
Java version control with jenv
Troubleshooting with Java Flight Recorder
Streamline Java testing with Spock
Connect to DB with Java
Connect to MySQL 8 with Java
Error when playing with java
Using Mapper with Java (Spring)
Java study memo 2 with Progate
Getting Started with Java Basics
Seasonal display with Java switch