ansible安装tomcat一个很low的写法,后面再更新高级的写法

注:下面with_items显示不正常,具体请看图片~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
- hosts: all
   remote_user: root
   tasks:
   - name:  "复制jdk文件到目标服务器"
     copy:
       src: ./{{ item.src }}
       dest:  "{{ item.dest }}"
     with_items:
       - src: jdk-8u111-linux-x64.rpm
         dest:  /usr/local/src/
       - src: apache-tomcat-8.0.30. tar .gz
         dest:  /usr/local/src/
       - src: java18.sh
         dest:  /etc/profile .d/
   - name:  "安装jdk"
     yum:
       name:  /usr/local/src/jdk-8u111-linux-x64 .rpm
       state: present
   - name:  "配置java环境变量"
     shell:  "source /etc/profile"
   - name:  "安装tomcat"
     unarchive:
       src:  /usr/local/src/apache-tomcat-8 .0.30. tar .gz
       dest:  /usr/local/
       copy: no
   - name:  "为tomcat创建软链接"
     file :
       src:  /usr/local/apache-tomcat-8 .0.30
       dest:  /usr/local/tomcat
       state: link
   - name:  "给sh脚本增加执行权限"
     shell:  'find /usr/local/tomcat/bin/ -name "*.sh" | xargs chmod +x'
   - name:  "启动tomcat"
     shell:  'nohup /usr/local/tomcat/bin/startup.sh &'

wKiom1moNzKQB3TvAACNgmz4c88967.png

以上playbook经过测试是没有问题的,后面学习后会给上传更严谨的写法~