写一个安装jdk的playbook
时间: 2024-05-05 20:19:38 浏览: 78
playbook+roles安装nginx,tomcat,jdk,mysql合集
好的,我可以为你编写一个安装JDK的Ansible Playbook,以下是代码:
```
- name: Install JDK
hosts: all
become: yes
vars:
jdk_version: "11.0.11"
jdk_home: "/usr/java/latest"
tasks:
- name: Download JDK
get_url:
url: "https://download.java.net/java/GA/jdk{{ jdk_version }}/9/GPL/openjdk-{{ jdk_version }}_linux-x64_bin.tar.gz"
dest: "/tmp/openjdk-{{ jdk_version }}_linux-x64_bin.tar.gz"
- name: Create JDK dir
file:
path: "{{ jdk_home }}"
state: directory
- name: Extract JDK tarball
unarchive:
src: "/tmp/openjdk-{{ jdk_version }}_linux-x64_bin.tar.gz"
dest: "{{ jdk_home }}"
remote_src: yes
extra_opts: [--strip-components=1]
- name: Set JDK environment variables
lineinfile:
path: /etc/profile
line: "export JAVA_HOME={{ jdk_home }}"
become: yes
- name: Load JDK environment variables
shell: source /etc/profile
```
这个Playbook会下载JDK,创建JDK目录,解压JDK并设置环境变量。你可以根据自己的需要修改变量和路径。
阅读全文