六、安装OracleJDK
下载jdk安装文件,放到/opt中,将文件解压到/usr/local下后,修改/etc/profile文件中环境参数,实现java的安装。
创建jdk.yml文件
---- hosts: alltasks:- name: copy and unzip jdkunarchive:src: "/opt/jdk-8u351-linux-x64.tar.gz"dest: "/usr/local/"- name: chmod binfile:dest: "/usr/local/jdk1.8.0_351/bin"mode: 0755recurse: yes- name: set jdk envlineinfile:dest: /etc/profileline: "{{ item }}"state: presentloop:- "export JAVA_HOME=/usr/local/jdk1.8.0_351"- "export PATH=$JAVA_HOME/bin:$PATH"
执行安装
ansible-playbook /root/ansible/jdk.yml
确认java是否安装正常。
java -version