ansible 批量部署tomcat
ansible-playbook -v -i ip.txt installtomcatold.yml
[root@Jenkins tomcatinstall]# cat installtomcatold.yml
---
- hosts: all
remote_user: root
gather_facts: no
tasks:
- name: "在目标服务器上创建tomcat存放路径"
file:
path: "/opt/tomcat"
state: "directory"
owner: "root"
group: "root"
- name: "将tomcat包从ansible源机器拷贝至目标服务器的文件夹下"
copy:
src: "/root/ansible/tomcatinstall/apache-tomcat-8.0.43.tar.gz"
dest: "/opt/tomcat"
owner: root
group: root
mode: 755
- name: "解压目标服务器上的tomcat压缩包"
shell: cd /opt/tomcat; tar zxvf apache-tomcat-8.0.43.tar.gz
- name: "将解压后的tomcat文件夹重命名"
shell: cd /opt/tomcat; mv apache-tomcat-8.0.43 tomcat
- name: "删除旧的tomcat压缩包"
shell: rm -rf /opt/tomcat/apache-tomcat-8.0.43.tar.gz
- name: "删除tomcat路径下无用的日志文件和war包"
shell: rm -rf /opt/tomcat/tomcat/webapps/*; rm -rf /opt/tomcat/tomcat/logs/*