Ansible-playbook JDK Installation

Source: Internet
Author: User

Ansible-playbook JDK Installation


The directory structure for JDK role is as follows:

[Email protected] roles]# tree Jdkjdk├──defaults├──files│└──jdk-8u101-linux-x64.tar.gz├──handlers├──meta├──tasks │└──main.yml├──templates└──vars└──main.yml

#vars下面的忽略, that's the one that was written before.

The contents of the task file are as follows:

[[email protected] tasks]# cat main.yml - name:  copy  jdk-8u101-linux-x64.tar.gz remote hosts  copy: src=jdk-8u101-linux-x64.tar.gz  Dest=/usr/local/- name: tar jdk-8u101-linux-x64.tar.gz  shell: chdir=/usr/local  tar zxf jdk-8u101-linux-x64.tar.gz- name: soft link  file: src=/ Usr/local/jdk1.8.0_101 dest=/usr/local/java state=link- name: java_profile config   shell: /bin/echo {{ item }} >> /etc/profile &&  source /etc/profile  with_items:    - export java_home=/usr /local/java    - export jre_home=/usr/local/java/jre    -  export classpath=.:\ $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar:\ $JRE _home/lib:\ $CLASSPATH     - export &nbSp Path=\ $JAVA _home/bin:\ $PATH


#注意这块有个坑啊, special characters must be anti-slash \ Screen character special meaning, tried several times to find this problem, including gather_facts off also useless, to the target host changed, and finally found to \.


#2台机器只跑一台:

[[Email protected] ansible]# ansible-playbook jdk.yml -l 192.168.121.129play  [test] ********************************************************************task [jdk :  copy jdk-8u101-linux-x64.tar.gz remote hosts] **********************changed: [ 192.168.121.129]task [jdk : tar jdk-8u101-linux-x64.tar.gz] ************************* Changed: [192.168.121.129] [warning]: consider using unarchive module  rather than running tartask [jdk : soft link] ****************** Changed: [192.168.121.129]task [jdk : java_profile  config] ***********************************************changed: [192.168.121.129] =>   (Item=export java_home=/usr/local/java) changed: [192.168.121.129] =>  (item=export  jre_home=/usr/lOCAL/JAVA/JRE) changed: [192.168.121.129] =>  (item=export classpath=.:\ $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar:\ $JRE _home/lib:\ $CLASSPATH) changed: [192.168.121.129]  =>  (item=export path=\ $JAVA _home/bin:\ $PATH) play recap ************************** 192.168.121.129             : ok=4    changed=4    unreachable=0     failed=0

#环境变量文件:

Cat/etc/profile-----Export Java_home=/usr/local/javaexport jre_home=/usr/local/java/jreexport CLASSPATH=.: $JAVA _ Home/lib/dt.jar:/lib/tools.jar: $JRE _home/lib: $CLASSPATHexport path= $JAVA _home/bin: $PATH

#测试java的版本:

[[Email protected]_clent ~]# java-versionjava Version "1.8.0_101" Java (TM) SE Runtime Environment (build 1.8.0_101-b13) Ja VA HotSpot (TM) 64-bit Server VM (build 25.101-b13, Mixed mode)



This article is from the "LINUX Super Dream" blog, make sure to keep this source http://215687833.blog.51cto.com/6724358/1887057

Ansible-playbook JDK Installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.