Ansible-playbook tomcat部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ansible-playbook tomcat部署相关的知识,希望对你有一定的参考价值。
Ansible-playbook tomcat部署
#目录树结构如下:
[[email protected] roles]# tree tomcat tomcat ├── defaults ├── files │ └── apache-tomcat-7.0.63.zip ├── handlers │ └── main.yml ├── meta ├── tasks │ └── main.yml ├── templates └── vars └── main.yml
#handlers这块并没有用上
# cat handlers/main.yml - name: stop tomcat shell: "ps -ef |grep tomcat |grep -v grep |awk ‘{print $2}‘ |xargs kill -9" - name: start tomcat shell: chdir=/usr/local/tomcat/bin sh ./startup.sh
#启动tomcat这块我发现首次启动用startup.sh启动貌似不行,提示让用catalina.sh启动。
# cat tasks/main.yml - name: 将tomcat压缩包copy到远程主机 apache-tomcat-7.0.63.zip copy: src=apache-tomcat-{{ tomcat_version }}.zip dest=/data - name: 解压tomcat压缩包apache-tomcat-7.0.63.zip shell: cd /data && unzip apache-tomcat-{{ tomcat_version }}.zip - name: 将tomcat压缩包 重新命名为 tomcat file: src=/data/apache-tomcat-{{ tomcat_version }} dest=/data/tomcat state=link - name: add /etc/profile shell: chdir=/data/tomcat/bin sed -i ‘1a source /etc/profile‘ startup.sh - name: 首次启动tomcat shell: chdir=/data/tomcat/bin nohup ./catalina.sh start & - name: remove apache-tomcat-7.0.63.zip file: path=/data/apache-tomcat-{{ tomcat_version }}.zip state=absent
# cat vars/main.yml
tomcat_version: 7.0.63
#roles可以加个jdk,和tomcat一块安装。
#cat tomcat.yml - hosts: test remote_user: root roles: - tomcat
#tomcat playbook运行过程如下:
# ansible-playbook tomcat.yml -l 192.168.121.129 PLAY [test] ******************************************************************** TASK [setup] ******************************************************************* ok: [192.168.121.129] TASK [tomcat : 将tomcat压缩包copy到远程主机 apache-tomcat-7.0.63.zip] ******************* changed: [192.168.121.129] TASK [tomcat : 解压tomcat压缩包apache-tomcat-7.0.63.zip] **************************** changed: [192.168.121.129] TASK [tomcat : 将tomcat压缩包 重新命名为 tomcat] **************************************** changed: [192.168.121.129] TASK [tomcat : add /etc/profile] *********************************************** changed: [192.168.121.129] [WARNING]: Consider using template or lineinfile module rather than running sed TASK [tomcat : 首次启动tomcat] ***************************************************** changed: [192.168.121.129] TASK [tomcat : remove apache-tomcat-7.0.63.zip] ******************************** changed: [192.168.121.129] PLAY RECAP ********************************************************************* 192.168.121.129 : ok=7 changed=6 unreachable=0 failed=0
#可以看到目标机java的pid,表示tomcat已经启动成功。
[[email protected]_clent ~]# jps 48781 Jps 26863 Bootstrap
本文出自 “LINUX Super梦” 博客,请务必保留此出处http://215687833.blog.51cto.com/6724358/1888534
以上是关于Ansible-playbook tomcat部署的主要内容,如果未能解决你的问题,请参考以下文章