ansible 安装jdk
1、上传文件到ansible端上
/data/jdk/jdk-8u341-linux-x64.tar.gz(下载地址:)
2、编辑jdk.yml文件
vim jdk.yml
【
---
- hosts: 192.168.59.103
remote_user: root
tasks:
- name: mkdir
file: name=/data/jdk state=directory
- name: copy file
copy: src=/data/jdk/jdk-8u341-linux-x64.tar.gz dest=/data/jdk/
- name: tar
unarchive: src=/data/jdk/jdk-8u341-linux-x64.tar.gz dest=/usr/local/ copy=no
#不能用$JAVA_HOME参数,否则识别不出来
- name: echo1
shell: echo "JAVA_HOME=/usr/local/jdk1.8.0_341" >> /etc/profile
#shell: sed -i '$aJAVA_HOME=/usr/local/jdk1.8.0_341' >> /etc/profile
- name: echo2
shell: echo "CLASSPATH=/usr/local/jdk1.8.0_341/lib/" >> /etc/profile
#shell: sed -i '$aCLASSPATH=/usr/local/jdk1.8.0_341/lib/' >> /etc/profile
- name: echo3
shell: echo "PATH=$PATH:/usr/local/jdk1.8.0_341/bin" >> /etc/profile
#shell: sed -i '$aPATH=$PATH:/usr/local/jdk1.8.0_341/bin' >> /etc/profile
- name: echo4
shell: echo "export JAVA_HOME CLASSPATH PATH" >> /etc/profile
#shell: sed -i '$aexport JAVA_HOME CLASSPATH PATH' >> /etc/profile
- name: source
shell: source /etc/profile
】
3、验证
ansible-playbook jdk.yml