Ansible-playbook Tomcat Deployment
#The directory tree structure is as follows:
[[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
#handlersThis is not used
# 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
#Starting tomcat I found that starting up with startup.sh didn't seem to work for the first time. I was prompted to start with catalina.sh.
# cat tasks / main.yml
-name: Copy the tomcat archive to the remote host apache-tomcat-7.0.63.zip
copy: src = apache-tomcat-{{tomcat_version}}. zip dest = / data
-name: Extract the tomcat archive apache-tomcat-7.0.63.zip
shell: cd / data && unzip apache-tomcat-{{tomcat_version}}. zip
-name: Rename tomcat archive 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: start tomcat for the first time
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 can add a jdk and install it with tomcat.
#cat tomcat.yml
- hosts: test
remote_user: root
roles:
- tomcat
#tomcat Playbook Run the following procedure:
# ansible-playbook tomcat.yml -l 192.168.121.129
PLAY [test] ********************************************** **********************
TASK [setup] ********************************************** *********************
ok: [192.168.121.129]
TASK [tomcat: Copy the tomcat archive to the remote host apache-tomcat-7.0.63.zip] *******************
changed: [192.168.121.129]
TASK [tomcat: Extract the tomcat archive apache-tomcat-7.0.63.zip] ****************************
changed: [192.168.121.129]
TASK [tomcat: Rename tomcat archive 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: start tomcat for the first time] ************************************** ***********
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
#You can see the pid of the target machine java, which means that tomcat has been started successfully.
[[email protected]_clent ~]# jps
48781 Jps
26863 Bootstrap
This article is from the "LINUX Super Dream" blog, make sure to keep this source http://215687833.blog.51cto.com/6724358/1888534
Ansible-playbook Tomcat Deployment