Ansible-playbook常用脚本安装JDK

一、需要在Anisble主服务器上配置好hosts

二、清除/etc/profile中的JAVA配置信息

三、安装rpm包

四、配置java环境变量到/etc/profile中。

- hosts: jdk
  remote_user: root
  tasks:
   - name: copy jdk rpm package
     copy: src=/etc/ansible/roles/files/jdk-8u321-linux-x64.rpm dest=/opt mode=0775
   - name: delete line
     lineinfile: dest=/etc/profile regexp='(.*)JAVA_HOME(.*)' state=absent
   - name: install rpm
     shell: cd /opt && rpm -ivh jdk-8u321-linux-x64.rpm
   - name: set jdk env
     lineinfile: dest=/etc/profile line="{{item.value}}" state=present
     with_items:
     - {value: "export JAVA_HOME=/usr/java/jdk1.8.0_321-amd64"}
     - {value: "export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar"}
     - {value: "export PATH=$JAVA_HOME/bin:$PATH"}
   - name: source profile
     shell: source /etc/profile

你可能感兴趣的:(Ansible,java,开发语言)