ansible 安装jdk

2022-06-24  本文已影响0人  su酥饼

注此方法为离线安装,jdk安装包需要提前准备好。
cat host_jdk

[jdk]
10.10.2.11
10.10.2.12
10.10.2.13

cat jdk_install.yml

- hosts: jdk
  remote_user: root
  gather_facts: false
  tasks:
    - name: mkdir java
      file: 
        path: /usr/local/java
        state: directory
  
    - name: copy jdk
      unarchive: src=jdk-8u161-linux-x64.tar.gz dest=/usr/local/java
      
    - name: append JAVA_HOME
      shell: echo "JAVA_HOME=/usr/local/java/jdk1.8.0_161" >> /etc/profile
      
    - name: append JRE_HOME
      shell: echo "JRE_HOME=$JAVA_HOME/jre" >> /etc/profile
      
    - name: append CLASSPATH
      shell: echo "CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/rt.jar" >> /etc/profile
      
    - name: append PATH
      shell: echo "export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin" >> /etc/profile
      
    - name: export PATH
      shell: echo "export JAVA_HOME JRE_HOME CLASSPATH PATH" >> /etc/profile
      
    - name: edit env
      shell: source /etc/profile

执行剧本

ansible-playbook -i jdk_host jdk_install.yml

查看

java --version

#如果提示找不到命令,手动 source /etc/profile
上一篇下一篇

猜你喜欢

热点阅读