Ansible is useful for automating server construction, but there are some tough points when trying to install the JDK. There was not much information in Japanese about how to solve it, so I will briefly summarize it.
As you can see from the download screen, you need to agree to the license to download the JDK.
In Ansible, you can easily download middleware using the yum
module and the get_url
module, but in the case of the JDK, you cannot download it obediently. You can work around this issue by giving the cookie that it has been activated.
Cookies can be set in the headers
option of the get_url
module.
headers: "Cookie:' gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie'"
In addition, Java downloads are done over SSL, so you have to get past certificate issues.
The get_url
module has an option called validate_certs
, which can be avoided by setting no
here (it's an option that literally skips authentication, so use it only for trusted sites. ).
validate_certs: no
You can download Java with the following script.
- name: download JDK
get_url:
url: "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm"
dest: "/opt/jdk-8u144-linux-x64.rpm"
headers: "Cookie:' gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie'"
validate_certs: no
owner: root
group: root
mode: 744
- name: install JDK from a local file
yum:
name: "/opt/jdk-8u144-linux-x64.rpm"
state: present
Recommended Posts