ansible roles實踐——安裝java
阿新 • • 發佈:2018-03-12
sta sts AI AR .gz too lock clas necessary
1、tasks/main.yml
---
- name: mkdir necessary directory
file: path=/usr/java/ state=directory mode=0755- name: unzip jdk
unarchive: src={{ jdk_package_name }} dest=/usr/java/- name: set env
lineinfile: dest={{ env_file }} insertafter={{ item.position }} line={{ item.value }} state=present
with_items:
- {position: EOF,value: "\n"}
- {position: EOF,value: "export JAVA_HOME=/usr/java/{{ jdk_version }}"}
- {position: EOF,value: "export PATH=$JAVA_HOME/bin/:$PATH"}
- {position: EOF,value: "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar"}- name: enforce env
shell: source {{ env_file }}
2、vars/main.yml
---jdk_package_name: jdk-8u121-linux-x64.tar.gz
env_file: /etc/profile
jdk_version: jdk1.8.0_121
3、入口jdk.yml
---- hosts: 172.16.2.241
remote_user: root
roles:
- jdk
ansible roles實踐——安裝java