我们需要用到的文件jdk以及tomcat安装包
下载链接:https://pan.baidu.com/s/1sjG8Yl8k-SUbOv7KwKXZMA
提取码:t71z
- 准备n台机器(我这里就简单部署三台机器)
ansible的安装部署以及配置可以看博主之前的文章自动化运维工具-ansible部署
ansible机器 :192.168.240.140
目标主机1:192.168.240.141
目标主机2:192.168.240.142 - 编辑配置文件
vim /etc/ansible/hosts
- 编写tomcat.yml文件
shell
---
- name: tomcat
hosts: weball
user: root
vars_files:
- /tmp/varsfile/tomcat_vars.yml
tasks:
- name: jdk
copy: src={{jdk_src_path}} dest={{jdk_dest_path}}
- name: rpm
shell: rpm -ivh {{jdk_src_path}}
- name: echo
shell: echo {{item}} >> /etc/profile
with_items:
- export JAVA_HOME=/usr/java/default
- export PATH=$PATH:$JAVA_HOME/bin
- export CLASSPATH=.
- name: source
shell: source /etc/profile
- name: copy
copy: src={{copy_src_path}} dest={{copy_dest_path}}
- name: tar
shell: tar -zxvf {{copy_src_path}} -C /tmp
- name: start
shell: nohup {{copy_name}}/bin/startup.sh &
- tomcat_vars.yml参数文件
shell
jdk_src_path: /tmp/jdk-8u171-linux-x64.rpm
jdk_dest_path: /tmp/
copy_src_path: /tmp/apache-tomcat-8.5.78.tar.gz
copy_dest_path: /tmp/
copy_name: /tmp/apache-tomcat-8.5.78
- 检查脚本
shell
[root@localhost tmp]# ansible-playbook --syntax-check tomcat.yml
- 执行tomcat.yml
shell
ansible-playbook tomcat.yml
- 验证tomcat部署
在浏览器输入目标主机IP:8080
例:192.168.240.141:8080
那么至此,ansible(playbook)部署tomcat就完成了,觉得有帮助点赞关注加收藏,谢谢小伙伴们的支持!!!