Bootstrap

ansible-playbook 搭建JDK

文件目录结构
在这里插入图片描述
main.yml

#首先检测有无java,没有才会安装,有了就直接跳过
- name: Create installation directory
  file: path=/var/www/ state=directory

- name: Check java
  shell: . /etc/profile && java -version
  register: result
  ignore_errors: True

- name: Decompression jdk.tar.gz
  unarchive: src=jdk-8u362-linux-x64.tar.gz dest=/var/www/
  when: result.failed == True

- name: Add environment variable
  shell: echo {{ item }} >> /etc/profile
  with_items:
    - export JAVA_HOME=/var/www/jdk1.8.0_362
    - export PATH=\$JAVA_HOME/bin:\$PATH
  when: result.failed == True

jdk.yml
在这里插入图片描述
最后执行

ansible-playbook -i hosts jdk.yml
;