ansible-playbook 部署tomcat簡單示例
阿新 • • 發佈:2018-01-17
files 設置變量 ins code chdir 設置 zhong 啟動 work
[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 /root/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
ansible-playbook 部署tomcat簡單示例