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.gzenv_file: /etc/profilejdk_version: jdk1.8.0_121
3、入口jdk.yml
---- hosts: 172.16.2.241 remote_user: root roles: - jdk
原文地址:https://www.cnblogs.com/fanren224/p/8550977.html
时间: 2024-10-29 14:55:30