ansible-playbook 单个yml文件部署tomcat简单示例

#单yaml配置
[root@jenkins pb]# cat tomcat.yml --- - hosts: eee vars:                                           #设置变量 war_files: /var/lib/jenkins/workspace/java_test/target/huizhongph.war    #本地war包路径 tomcat_root: /root/tomcat_hzph_pc_9090/webapps/huizhongph           #远端tomcat目录 tasks: - name: 关闭tomcat shell: chdir={{ tomcat_root }}/../../bin nohup ./shutdown.sh & - name: backup old code                            #备份当前正在使用的源码 shell: chdir={{ tomcat_root }}/../ tar -czf /bak/huizhongph_$(date -d "today" +"%Y%m%d_%H%M%S").tar.gz huizhongph & - name: 删除旧版本的配置文件 file: state: absent dest: "{{ tomcat_root }}" - name: clean cache|清除缓存 shell: chdir={{ tomcat_root }}/../../ nohup rm -rf work & - name: 创建目录 file: state: directory dest: "{{ tomcat_root }}" mode: 755 - name: 解压war包 unarchive: src: "{{ war_files }}" dest: "{{ tomcat_root }}" copy: yes - name: 覆盖(替换)配置文件 copy: src=/root/{{ item }} dest=/root/test/{{ item }}    #这里指定配置文件的路径为本地路径 with_items:                              #要替换的配置文件 - a.txt - b.txt - c.txt - d.txt - shell (目录) - name: 启动tomcat shell: chdir={{ tomcat_root }}/../../bin nohup ./startup.sh &

执行命令

ansible-playbook -i /xxx/xxx/host tomcat.yml

 回滚操作目前还没有确定用哪种,暂时没贴

原文地址:https://www.cnblogs.com/FRESHMANS/p/8304279.html